See Also: DateFormat Members
Formats or parses dates and times.
This class provides factories for obtaining instances configured for a specific locale. The most common subclass is Java.Text.SimpleDateFormat.
This code:
java Example
DateFormat[] formats = new DateFormat[] {
DateFormat.getDateInstance(),
DateFormat.getDateTimeInstance(),
DateFormat.getTimeInstance(),
};
for (DateFormat df : formats) {
System.out.println(df.format(new Date(0)));
df.setTimeZone(TimeZone.getTimeZone("UTC"));
System.out.println(df.format(new Date(0)));
}
Produces this output when run on an en_US device in the America/Los_Angeles time zone:
java Example
Dec 31, 1969 Jan 1, 1970 Dec 31, 1969 4:00:00 PM Jan 1, 1970 12:00:00 AM 4:00:00 PM 12:00:00 AM