Here you can find the source of dateToStr(Date date, String format)
public static String dateToStr(Date date, String format)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static String dateToStr(Date date, String format) { String _timeZone = System.getProperty("user.timezone"); TimeZone timeZone = null; if (_timeZone == null || "".equals(_timeZone) || "UTC".equals(_timeZone)) { timeZone = TimeZone.getDefault(); } else {// ww w.j a va2 s . co m timeZone = TimeZone.getTimeZone("Asia/Shanghai"); } SimpleDateFormat dateFormat = new SimpleDateFormat(format); dateFormat.setTimeZone(timeZone); return dateFormat.format(date); } }