Java Now now(String pattern)

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

Description

now

License

Apache License

Declaration

public static String now(String pattern) 

Method Source Code


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

import java.text.DateFormat;

import java.text.SimpleDateFormat;

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

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

    public static String now(String pattern) {
        DateFormat dateFormat = getFormat(pattern);
        return dateFormat.format(new Date());
    }//www. j ava 2  s. c o m

    private static DateFormat getFormat(String pattern) {
        DateFormat dateFormat;
        if (!patterns.containsKey(pattern)) {
            dateFormat = new SimpleDateFormat(pattern);
            patterns.put(pattern, dateFormat);
        }
        dateFormat = patterns.get(pattern);
        return dateFormat;
    }
}

Related

  1. now(String dateFormat)
  2. now(String dateFormat)
  3. now(String dateFormat)
  4. now(String dateFormat)
  5. now(String formatStr)
  6. now(String s, Date date)
  7. now_TimeZone_BY()
  8. nowAs14CharString()
  9. nowAsAnsiDate()