DateFormat is an abstract class to format and parse dates and times.
The getDateInstance()
method returns an instance of DateFormat.
static final DateFormat getDateInstance() static final DateFormat getDateInstance(int style) static final DateFormat getDateInstance(int style, Locale locale)
The argument style is one of the following values: DEFAULT, SHORT, MEDIUM, LONG, or FULL.
// Demonstrate date formats. 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;//from w w w . j ava2s.c om df = DateFormat.getDateInstance(DateFormat.SHORT, Locale.JAPAN); System.out.println("Japan: " + df.format(date)); df = DateFormat.getDateInstance(DateFormat.MEDIUM, Locale.KOREA); System.out.println("Korea: " + df.format(date)); df = DateFormat.getDateInstance(DateFormat.LONG, Locale.UK); System.out.println("United Kingdom: " + df.format(date)); df = DateFormat.getDateInstance(DateFormat.FULL, Locale.US); System.out.println("United States: " + df.format(date)); } }