Java Time Now getNowDefault()

Here you can find the source of getNowDefault()

Description

get Now Default

License

Apache License

Declaration

public static String getNowDefault() 

Method Source Code

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

import java.text.SimpleDateFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class Main {
    private static Map<String, SimpleDateFormat> formats = new HashMap();

    public static String getNowDefault() {
        return getNow("yyyyMMddHHmmss");
    }// w w  w .j av  a  2  s . c o m

    public static String getNow(String pattern) {
        return getFormatTimeString(new Date(), pattern);
    }

    public static String getFormatTimeString(Date date, String pattern) {
        SimpleDateFormat sDateFormat = getDateFormat(pattern);

        synchronized (sDateFormat) {
            return sDateFormat.format(date);
        }
    }

    public static SimpleDateFormat getDateFormat(String pattern) {
        SimpleDateFormat sDateFormat = (SimpleDateFormat) formats.get(pattern);
        if (sDateFormat == null) {
            sDateFormat = new SimpleDateFormat(pattern);
            formats.put(pattern, sDateFormat);
        }
        return sDateFormat;
    }
}

Related

  1. getNowDateTime()
  2. getNowDateTime()
  3. getNowDateTime(String strScheme)
  4. getNowDateTimeStrConcise()
  5. getNowDayTimeLong()
  6. getNowFileFormat()
  7. getNowFormatLog()
  8. getNowFormattedDateTimeStr(String pattern)
  9. getNowHour()