Java Date Now getCurrentTime(String formatter)

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

Description

get system time with a formatter

License

Open Source License

Parameter

Parameter Description
formatter : yyyyMMddHHmmss

Return

String

Declaration

public static String getCurrentTime(String formatter) 

Method Source Code


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

import java.text.SimpleDateFormat;

import java.util.TimeZone;

public class Main {
    private final static String DEFAULT_DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";

    /**/*from  w w  w  .  ja v  a 2 s  . c  om*/
    * get system time with a default date format
    * @return String
    */
    public static String getCurrentTime() {
        return getCurrentTime(getDefaultFormat());
    }

    /**
    * get system time with a formatter
    * @param  formatter : yyyyMMddHHmmss
    * @return String
    */
    public static String getCurrentTime(String formatter) {
        SimpleDateFormat fmt = new SimpleDateFormat(formatter);
        fmt.setTimeZone(getTimeZone());

        return fmt.format(new java.util.Date(System.currentTimeMillis()));
    }

    /**
    * get default date format : yyyyMMdd, yyyy-MM-dd HH:mm:ss
    * @return String
    */
    public static String getDefaultFormat() {
        return DEFAULT_DATE_FORMAT;
        //return BasePropManager.getBaseProperties("Environment").getString("date.formatter", DEFAULT_DATE_FORMAT);
    }

    /**
    * get default SimpleTimeZone (System Properties)
    * @return SimpleTimeZone
    */
    public static TimeZone getTimeZone() {
        return TimeZone.getDefault();
    }
}

Related

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