// File: TestDate10.java (Module 8) // // Author: Rahul Simha // Created: October 6 // // Illustrates pre-defined formats in DateFormat. import java.util.*; import java.text.*; public class TestDate10 { public static void main (String[] argv) { // Create a date. GregorianCalendar cal = new GregorianCalendar ( 1998, // Year GregorianCalendar.OCTOBER, // Month 5, // Day 14, // Hour of day (2 pm) 30, // Minutes 22 // Seconds ); // Extract the date. Date d = cal.getTime(); // Use the default format. DateFormat def = DateFormat.getDateInstance (DateFormat.DEFAULT); String s = def.format (d); System.out.println ("DEFAULT: " + s); // The full format. DateFormat full = DateFormat.getDateInstance (DateFormat.FULL); s = full.format (d); System.out.println ("FULL: " + s); // The long format. DateFormat lg = DateFormat.getDateInstance (DateFormat.LONG); s = lg.format (d); System.out.println ("LONG: " + s); // Medium and default are the same. DateFormat med = DateFormat.getDateInstance (DateFormat.MEDIUM); s = med.format (d); System.out.println ("MEDIUM: " + s); // Short format. DateFormat sh = DateFormat.getDateInstance (DateFormat.SHORT); s = sh.format (d); System.out.println ("SHORT: " + s); } }