Java Date Now getCurrentTimeInString(SimpleDateFormat dateFormat)

Here you can find the source of getCurrentTimeInString(SimpleDateFormat dateFormat)

Description

get current time in milliseconds

License

Apache License

Declaration

public static String getCurrentTimeInString(SimpleDateFormat dateFormat) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.SimpleDateFormat;
import java.util.Date;

public class Main {
    public static final SimpleDateFormat DATE_FORMAT_DATE_S = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    /**/*  w  w w.  j av a  2  s. c  om*/
     * get current time in milliseconds, format is {@link #DEFAULT_DATE_FORMAT}
     * 
     * @return
     */
    public static String getCurrentTimeInString() {
        return getTime(getCurrentTimeInLong());
    }

    /**
     * get current time in milliseconds
     * 
     * @return
     */
    public static String getCurrentTimeInString(SimpleDateFormat dateFormat) {
        return getTime(getCurrentTimeInLong(), dateFormat);
    }

    /**
     * long time to string
     * 
     * @param timeInMillis
     * @param dateFormat
     * @return
     */
    public static String getTime(long timeInMillis, SimpleDateFormat dateFormat) {
        return dateFormat.format(new Date(timeInMillis));
    }

    /**
     * long time to string, format is {@link #DEFAULT_DATE_FORMAT}
     * 
     * @param timeInMillis
     * @return
     */
    public static String getTime(long timeInMillis) {
        return getTime(timeInMillis, DATE_FORMAT_DATE_S);
    }

    /**
     * get current time in milliseconds
     * 
     * @return
     */
    public static long getCurrentTimeInLong() {
        return System.currentTimeMillis();
    }
}

Related

  1. getCurrentTimeForLog()
  2. getCurrentTimeForName()
  3. getCurrentTimeForUseInAFileName()
  4. getCurrentTimeInMySqlTime()
  5. getCurrentTimeInMySqlTime()
  6. getCurrentTimeInString(String format)
  7. getCurrentTimeNoHour()
  8. getCurrentTimeNumber()
  9. getCurrentTimeOfDay()