Here you can find the source of formatDate(Date d, String pattern, TimeZone tz)
public static String formatDate(Date d, String pattern, TimeZone tz)
//package com.java2s; /******************************************************************************* * Copyright SemanticBits, Northwestern University and Akaza Research * //from w w w.ja v a 2 s . co m * Distributed under the OSI-approved BSD 3-Clause License. * See http://ncip.github.com/caaers/LICENSE.txt for details. ******************************************************************************/ import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { public static final String DATE_PATTERN = "MM/dd/yyyy"; public static final String DATE_WITH_DATETIME = "MM/dd/yyyy HH:mm"; public static String formatDate(Date d) { if (d.getHours() > 0 || d.getMinutes() > 0) return formatDate(d, DATE_WITH_DATETIME); return formatDate(d, DATE_PATTERN); } public static String formatDate(Date d, String pattern) { return formatDate(d, pattern, TimeZone.getDefault()); } public static String formatDate(Date d, String pattern, TimeZone tz) { //BJ: date formats are not thread safe. SimpleDateFormat df = new SimpleDateFormat(pattern); df.setTimeZone(tz); return df.format(d); } }