Here you can find the source of dateTimeToStr(Date date, String format)
public static String dateTimeToStr(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 dateTimeToStr(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 {/*from w w w. ja v a 2s .com*/ timeZone = TimeZone.getTimeZone("Asia/Shanghai"); } SimpleDateFormat dateFormat = new SimpleDateFormat(format); dateFormat.setTimeZone(timeZone); return dateFormat.format(date); } }