/** * Example of using DateFormat object * shows current date using all 4 styles * (short, medium, long and full). * * also shows how to specify the Locale, * in this case we use the predefined Locale * for France. */ import java.util.*; import java.text.*; class DateFormatPlay { public static void main(String [] args) { // get the current date/time Date now = new Date(); // try with each style (default Locale) showDate(DateFormat.SHORT,now); showDate(DateFormat.MEDIUM,now); showDate(DateFormat.LONG,now); showDate(DateFormat.FULL,now); // now try with the locale for france showDate(DateFormat.SHORT,now,Locale.JAPAN); showDate(DateFormat.MEDIUM,now,Locale.JAPAN); showDate(DateFormat.LONG,now,Locale.FRANCE); showDate(DateFormat.FULL,now,Locale.JAPAN); } /** * prints a date using the specified style and the default Locale * @param style style should be a valid DateFormat style value * @param d the point in time to be displayed. */ static void showDate( int style, Date d) { System.out.println( DateFormat.getDateInstance(style).format(d)); } /** * prints a date using the specified style and Locale * @param style style should be a valid DateFormat style value * @param d the point in time to be displayed. * @param l the Local to use when formating the date */ static void showDate( int style, Date d, Locale l) { System.out.println( DateFormat.getDateInstance(style,l).format(d)); } }