Java Time Now getNowString(String pattern)

Here you can find the source of getNowString(String pattern)

Description

get Now String

License

LGPL

Declaration

public static String getNowString(String pattern) 

Method Source Code

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

import java.text.SimpleDateFormat;

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

import java.util.Map;

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

    public static String getNowString(String pattern) {
        return getDateFormat(pattern).format(getNow());
    }/*from  w  w  w.  j ava  2 s. c  om*/

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

    public static Date getNow() {
        return new Date();
    }
}

Related

  1. getNowStr()
  2. getNowStr()
  3. getNowStrDateVerbose()
  4. getNowString()
  5. getNowString()
  6. getNowTime()
  7. getNowTime()
  8. getNowTime()
  9. getnowTime()