Here you can find the source of getToSecond()
public static String getToSecond()
//package com.java2s; //License from project: Apache License import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.TimeZone; public class Main { public final static String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; /**//from w w w. ja va 2s . co m * HH:mm:ss * */ public static String getToSecond() { SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); Date logonDate = Calendar.getInstance().getTime(); return sdf.format(logonDate); } public static Date getTime() { return Calendar.getInstance().getTime(); } public static Date getTime(int field, int diff) { Calendar c = Calendar.getInstance(); c.add(field, diff); return c.getTime(); } /** * get time of dstTimeZone from time of srcTimeZone * * @param time * @param srcTimeZone * @param dstTimeZone * @return Data */ private static Date getTime(Date time, TimeZone srcTimeZone, TimeZone dstTimeZone) { if (time == null) return null; DateFormat df = new SimpleDateFormat(DEFAULT_DATE_FORMAT); df.setTimeZone(dstTimeZone); String gmtTime = df.format(time); // convert current time to gmt time. df.setTimeZone(srcTimeZone); try { return df.parse(gmtTime); // gmt time to date } catch (ParseException e) { return time; } } public static Date parse(String date, String format) throws ParseException { if (date == null) return null; SimpleDateFormat fmt = new SimpleDateFormat(format); return fmt.parse(date); } }