001package edu.pdx.cs410J.datesAndText; 002 003import java.text.*; 004import java.util.*; 005 006/** 007 * This program reads a date and time from the command in 008 * <code>DateFormat.MEDIUM</code> format and prints it back out in all 009 * four formats. 010 */ 011public class FormattedDate { 012 013 /** 014 * The command line contains a date to be formatted 015 */ 016 public static void main(String[] args) { 017 StringBuffer sb = new StringBuffer(); 018 for (int i = 0; i < args.length; i++) { 019 sb.append(args[i] + " "); 020 } 021 Date date = null; 022 DateFormat df = 023 DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); 024 try { 025 date = df.parse(sb.toString().trim()); 026 027 } catch (ParseException ex) { 028 String s = "Bad date: " + sb; 029 System.err.println("** " + s); 030 System.exit(1); 031 } 032 033 df = DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT); 034 System.out.println("SHORT: " + df.format(date)); 035 036 df = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); 037 System.out.println("MEDIUM: " + df.format(date)); 038 039 df = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); 040 System.out.println("LONG: " + df.format(date)); 041 042 df = DateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL); 043 System.out.println("FULL: " + df.format(date)); 044 } 045 046}