package com.mindprod.inauguration;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import static java.lang.System.*;
/**
* Demonstrates parsing a date from a String.
*
* @author Roedy Green, Canadian Mind Products
* @version 1.3 2009-01-20 change to Obama
* @since 2000
*/
public final class InaugurationParse
{
/**
* mask for: Tuesday 2009-01-20 12:00 AM EST : Eastern Standard Time
* define an elaborate date format
*/
private static final SimpleDateFormat SDF_FANCY =
new SimpleDateFormat( "EEEE yyyy-MM-dd hh:mm aa zz : zzzzzz" );
/**
* mask for yyyy-mm-dd, define a plain format for the date
*/
private static final SimpleDateFormat SDF_PLAIN = new SimpleDateFormat( "yyyy-MM-dd" );
/**
* Main method.
*
* @param args not used
*/
public static void main( String[] args )
{
final String dateString = "2017-01-20";
TimeZone est = TimeZone.getTimeZone( "America/New_York" );
GregorianCalendar inauguration = new GregorianCalendar( est );
SDF_PLAIN.setCalendar( inauguration );
Date date = null;
try
{
date = SDF_PLAIN.parse( dateString );
inauguration.setTime( date );
}
catch ( ParseException e )
{
out.println( "bad date" );
}
out.println( "millis since 1970 is " + date.getTime() );
SDF_FANCY.setCalendar( inauguration );
out.println( "inauguration is "
+ SDF_FANCY.format( inauguration.getTime() ) );
}
}