Create new DateFormat instance

ReturnMethodSummary
static DateFormatgetDateInstance()Gets the date formatter with the default formatting style for the default locale.
static DateFormatgetDateInstance(int style)Gets the date formatter with the given formatting style for the default locale.
static DateFormatgetDateInstance(int style, Locale aLocale)Gets the date formatter with the given formatting style for the given locale.
static DateFormatgetDateTimeInstance()Gets the date/time formatter with the default formatting style for the default locale.
static DateFormatgetDateTimeInstance(int dateStyle, int timeStyle)Gets the date/time formatter with the given date and time formatting styles for the default locale.
static DateFormatgetDateTimeInstance(int dateStyle, int timeStyle, Locale aLocale)Gets the date/time formatter with the given formatting styles for the given locale.
static DateFormatgetInstance()Get a default date/time formatter that uses the SHORT style for both the date and the time.
static DateFormatgetTimeInstance()Gets the time formatter with the default formatting style for the default locale.
static DateFormatgetTimeInstance(int style)Gets the time formatter with the given formatting style for the default locale.
static DateFormatgetTimeInstance(int style, Locale aLocale)Gets the time formatter with the given formatting style for the given locale.
TimeZonegetTimeZone()Gets the time zone.
NumberFormatgetNumberFormat()Gets the number formatter which this date/time formatter uses to format and parse a time.
CalendargetCalendar()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
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.