Here you can find the source of formatDate(Date value, String pattern, TimeZone tz)
Parameter | Description |
---|---|
value | Date |
pattern | String the format pattern, for example, SimpleDate.PATTERN_US_DATE |
tz | TimeZone if null,will use the server's default timezone |
public static String formatDate(Date value, String pattern, TimeZone tz)
//package com.java2s; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; import java.util.TimeZone; public class Main { /**// w w w .jav a2 s . co m * format the date with the given pattern. * * @param value Date * @param pattern String the format pattern, for example, * SimpleDate.PATTERN_US_DATE * @param tz TimeZone if null,will use the server's default timezone * @return String the formated string */ public static String formatDate(Date value, String pattern, TimeZone tz) { if (value == null) { return ""; } SimpleDateFormat formater = new SimpleDateFormat(pattern, Locale.US); if (tz != null) { formater.setTimeZone(tz); } return formater.format(value); } }