// File: TestDate7.java (Module 8) // // Author: Rahul Simha // Created: October 6, 1998 // // Illustrates date formats. import java.util.*; import java.text.*; public class TestDate7 { 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 { // In the form "yyyy MMM dd" Date d1 = sdf1.parse ("1998 October 06"); System.out.println ("Date 1: " + d1); // In the form "EEEE, MMM dd, yyyy". // Note the commas. Date d2 = sdf2.parse ("Tuesday, Oct 06, 1998"); System.out.println ("Date 2: " + d2); // In the form "M d HH mm ss" Date d3 = sdf3.parse ("12 25 17 30 11"); System.out.println ("Date 3: " + d3); // Let's deliberately provide bad input. Date d4 = sdf1.parse ("October 6, 1998"); System.out.println ("Date 4: " + d4); } catch (ParseException e) { System.out.println (e); } } }