Here you can find the source of nowString(String pattern)
public static String nowString(String pattern)
//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 final Map<String, ThreadLocal<SimpleDateFormat>> pool = new HashMap<String, ThreadLocal<SimpleDateFormat>>(); private static final Object lock = new Object(); public static String nowString(String pattern) { return getDateFormat(pattern).format(new Date()); }/*from ww w . j a v a2 s. c o m*/ public static SimpleDateFormat getDateFormat(String pattern) { ThreadLocal<SimpleDateFormat> tl = pool.get(pattern); if (tl == null) { synchronized (lock) { tl = pool.get(pattern); if (tl == null) { final String p = pattern; tl = new ThreadLocal<SimpleDateFormat>() { protected synchronized SimpleDateFormat initialValue() { return new SimpleDateFormat(p); } }; pool.put(p, tl); } } } return tl.get(); } }