The getTimeInstance()
method from DateFormat returns an instance of DateFormat that can format time value.
static final DateFormat getTimeInstance() static final DateFormat getTimeInstance(int style) static final DateFormat getTimeInstance(int style, Locale locale)
The argument style is one of the following values: DEFAULT, SHORT, MEDIUM, LONG, or FULL.
// Demonstrate time 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;/* w w w . j av a2 s . c o m*/ 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)); } }