// File: TestDate8.java (Module 8) // // Author: Rahul Simha // Created: October 6, 1998 // // Illustrates date formats for printing. import java.util.*; import java.text.*; public class TestDate8 { public static void main (String[] argv) { // Create three patterns. SimpleDateFormat sdf1 = new SimpleDateFormat ("yyyy MMMM dd"), sdf2 = new SimpleDateFormat ("EEEE, MMM dd, yyyy"), sdf3 = new SimpleDateFormat ("M d HH mm ss"); // try is required: parse can throw an exception. try { // Format a date from an string. Date d1 = sdf1.parse ("1998 October 06"); System.out.println ("Date 1: " + d1); // Next, we will format the output differently. String s2 = sdf2.format (d1); System.out.println (s2); String s3 = sdf3.format (d1); System.out.println (s3); } catch (ParseException e) { System.out.println (e); } } }