Java Date Now getCurrentTime(String pattern)

Here you can find the source of getCurrentTime(String pattern)

Description

get Current Time

License

Open Source License

Declaration

public static String getCurrentTime(String pattern) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DateFormat;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {

    public static String getCurrentTime(String pattern) {
        if ("".equals(pattern) || null == pattern) {
            pattern = "yyyy-MM-dd HH:mm:ss";
        }/*  w  w w .jav a  2 s. c o  m*/
        DateFormat df = new SimpleDateFormat(pattern);
        return df.format(new Date());
    }

    public static String getCurrentTime() {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return df.format(new Date());
    }
}

Related

  1. getCurrentTime(String format)
  2. getCurrentTime(String format)
  3. getCurrentTime(String format)
  4. getCurrentTime(String formatter)
  5. getCurrentTime(String pattern)
  6. getCurrentTime(String pattern)
  7. getCurrentTime(String pattern)
  8. getCurrentTime(String timeFormat)
  9. getCurrentTime2MysqlDateTime()