Here you can find the source of getNow()
public static String getNow()
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.TimeZone; public class Main { /**//from ww w . java2 s. co m * Get date string as format of "yyyy-MM-dd HH:mm:ss.SSS" * @return */ public static String getNow() { SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); sdf.setTimeZone(getDefaultTimeZone()); return sdf.format(getCalendar().getTime()); } /** * Get default time zone of China * @return default time zone */ public static TimeZone getDefaultTimeZone() { return TimeZone.getTimeZone("GMT+8"); } /** * Get calendar instance with default time zone of GMT+8 * @return Calendar instance */ public static Calendar getCalendar() { TimeZone.setDefault(getDefaultTimeZone()); return Calendar.getInstance(); } }