Here you can find the source of getNowTime()
public static String getNowTime()
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Iterator; import java.util.Map; public class Main { private static String DEFAULT_PATTERN = "yyyy-MM-dd"; private static Map<String, SimpleDateFormat> formats; /**/*from ww w . ja va 2 s . co m*/ * @return yyyy-MM-dd HH:mm:ss */ public static String getNowTime() { return format(new Date(), "yyyy-MM-dd HH:mm:ss"); } /** * * @param date * * @param pattern * * @return */ public static String format(Date date, String pattern) { if (!formats.containsKey(pattern)) pattern = DEFAULT_PATTERN; DateFormat format = formats.get(pattern); return format.format(date); } /** * @param date * @return String */ public static String format(Date date) { Iterator<SimpleDateFormat> iter = formats.values().iterator(); while (iter.hasNext()) { return iter.next().format(date); } return null; } }