Java Date Now getCurrentTime()

Here you can find the source of getCurrentTime()

Description

get Current Time

License

Open Source License

Declaration

public static String getCurrentTime() 

Method Source Code

//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    public static String TIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
    public static String DATE_FORMAT = "yyyy-MM-dd";

    public static String getCurrentTime() {
        java.util.Calendar cal = java.util.Calendar.getInstance();
        return new java.text.SimpleDateFormat(TIME_FORMAT).format(cal.getTime());
    }/*from w  w w .j  a  v a  2s.c o  m*/

    public static String getCurrentTime(String parent) {
        java.util.Calendar cal = java.util.Calendar.getInstance();
        return new java.text.SimpleDateFormat(parent).format(cal.getTime());
    }

    public static String format(Date date, String pattern) {
        if (date == null) {
            return null;
        }
        SimpleDateFormat sf = new SimpleDateFormat(pattern);
        return sf.format(date);
    }

    public static String format(Date date) {
        return format(date, DATE_FORMAT);
    }
}

Related

  1. getCurrentTime()
  2. getCurrentTime()
  3. getCurrentTime()
  4. getCurrentTime()
  5. getCurrentTime()
  6. getCurrentTime()
  7. getCurrentTime()
  8. getCurrentTime()
  9. getCurrentTime()