Java Time Now currentTime()

Here you can find the source of currentTime()

Description

gets current time's string format like "HH:mm:ss"

License

Open Source License

Declaration

public static String currentTime() 

Method Source Code


//package com.java2s;

import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    /** The time format string:(HH:mm:ss) */
    public static final String TIME_FORMAT_STR = "HH:mm:ss";

    /**//from  ww w .ja v  a  2s.  c  om
     * gets current time's string format like "HH:mm:ss"
     * 
     * @return
     */
    public static String currentTime() {
        return getTimeFormat(now());
    }

    public static String getTimeFormat(java.util.Date date) {
        return getFormat(date, TIME_FORMAT_STR);
    }

    /**
     * Returns the current datetime.
     * 
     * @return the current datetime.
     */
    public static Date now() {
        return new Date(System.currentTimeMillis());
    }

    public static String getFormat(java.util.Date date, String parseFormat) {
        if (null == date) {
            return null;
        }
        if (null == parseFormat || "".equalsIgnoreCase(parseFormat)) {
            return date.toString();
        }
        return new SimpleDateFormat(parseFormat).format(date);
    }
}

Related

  1. currentTime()
  2. currentTime()
  3. currentTime()
  4. currentTime()
  5. currentTime()