Here you can find the source of format(long date, String pattern)
Parameter | Description |
---|---|
date | The date to format expressed in milliseconds. |
pattern | The pattern to use to format the date. |
public static String format(long date, String pattern)
//package com.java2s; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; public class Main { /**//from ww w .j ava2 s . c om * Format a date/time into a specific pattern. * * @param date The date to format expressed in milliseconds. * @param pattern The pattern to use to format the date. * @return The formatted date. */ public static String format(long date, String pattern) { return format(new Date(date), pattern); } /** * Format a date/time into a specific pattern. * * @param date The date to format expressed in milliseconds. * @param pattern The pattern to use to format the date. * @return The formatted date. */ public static String format(Date date, String pattern) { DateFormat df = createDateFormat(pattern); return df.format(date); } /** * Return a date format set to GMT time zone. * * @param pattern Tthe pattern used for date/time formatting. * @return The configured format for this pattern. */ private static DateFormat createDateFormat(String pattern) { SimpleDateFormat sdf = new SimpleDateFormat(pattern); TimeZone gmt = TimeZone.getTimeZone("GMT"); sdf.setTimeZone(gmt); sdf.setLenient(true); return sdf; } }