Create new DateFormat instance
static DateFormat getDateInstance()
- Gets the date formatter with the default formatting style for the default locale.
static DateFormat getDateInstance(int style)
- Gets the date formatter with the given formatting style for the default locale.
static DateFormat getDateInstance(int style, Locale aLocale)
- Gets the date formatter with the given formatting style for the given locale.
static DateFormat getDateTimeInstance()
- Gets the date/time formatter with the default formatting style for the default locale.
static DateFormat getDateTimeInstance(int dateStyle, int timeStyle)
- Gets the date/time formatter with the given date and time formatting styles for the default locale.
static DateFormat getDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale)
- Gets the date/time formatter with the given formatting styles for the given locale.
static DateFormat getInstance()
- Get a default date/time formatter that uses the SHORT style for both the date and the time.
static DateFormat getTimeInstance()
- Gets the time formatter with the default formatting style for the default locale.
static DateFormat getTimeInstance(int style)
- Gets the time formatter with the given formatting style for the default locale.
static DateFormat getTimeInstance(int style, Locale aLocale)
- Gets the time formatter with the given formatting style for the given locale.
TimeZone getTimeZone()
- Gets the time zone.
NumberFormat getNumberFormat()
- Gets the number formatter which this date/time formatter uses to format and parse a time.
Calendar getCalendar()
- Gets the calendar associated with this date/time formatter.
import java.text.DateFormat;
import java.util.Date;
import java.util.Locale;
public class Main{
public static void main(String args[]) {
Date date = new Date();
DateFormat df;
df = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.JAPAN);
System.out.println("Japan:" + df.format(date));
df = DateFormat.getTimeInstance(DateFormat.LONG, Locale.UK);
System.out.println("United Kingdom:" + df.format(date));
df = DateFormat.getTimeInstance(DateFormat.FULL, Locale.CANADA);
System.out.println("Canada:" + df.format(date));
}
}
The output:
Japan:10:02
United Kingdom:10:02:02 PDT
Canada:10:02:02 o'clock AM PDT
Home
Java Book
Essential Classes
Java Book
Essential Classes
DataFormat:
- DataFormat class
- Create new DateFormat instance
- Constants from DateFormat
- Format a date
- Get all locales
- Parse string to get Date