Here you can find the source of getGMT8Time()
public static Date getGMT8Time()
//package com.java2s; //License from project: Open Source License import java.util.Calendar; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Main { public static Date getGMT8Time() { Date gmt8 = null;//from w w w.j a v a2 s . co m try { Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT+8"), Locale.CHINESE); Calendar day = Calendar.getInstance(); day.set(Calendar.YEAR, cal.get(Calendar.YEAR)); day.set(Calendar.MONTH, cal.get(Calendar.MONTH)); day.set(Calendar.DATE, cal.get(Calendar.DATE)); day.set(Calendar.HOUR_OF_DAY, cal.get(Calendar.HOUR_OF_DAY)); day.set(Calendar.MINUTE, cal.get(Calendar.MINUTE)); day.set(Calendar.SECOND, cal.get(Calendar.SECOND)); gmt8 = day.getTime(); } catch (Exception e) { e.printStackTrace(); gmt8 = null; } return gmt8; } public static String getTime(java.util.Date date) { return format(date, "HH:mm:ss"); } public static String format(java.util.Date date, String format) { String result = ""; try { if (date != null) { java.text.DateFormat df = new java.text.SimpleDateFormat(format); result = df.format(date); } } catch (Exception e) { } return result; } }