I have a database field that contains a raw date field (stored as character data), such as
Friday, September 26, 2008 8:30 PM Eastern Daylight Time
I can parse this as a Date easily, with SimpleDateFormat
DateFormat dbFormatter = new SimpleDateFormat("EEEE, MMMM dd, yyyy hh:mm aa zzzz");
Date scheduledDate = dbFormatter.parse(rawDate);
What I'd like to do is extract a TimeZone object from this string. The default TimeZone in the JVM that this application runs in is GMT, so I can't use .getTimezoneOffset()
from the Date
parsed above (because it will return the default TimeZone).
Besides tokenizing the raw string and finding the start position of the Timezone string (since I know the format will always be EEEE, MMMM dd, yyyy hh:mm aa zzzz
) is there a way using the DateFormat/SimpleDateFormat/Date/Calendar API to extract a TimeZone object - which will have the same TimeZone as the String I've parsed apart with DateFormat.parse()
?
One thing that bugs me about Date
vs Calendar
in the Java API is that Calendar
is supposed to replace Date
in all places... but then they decided, oh hey let's still use Date
's in the DateFormat
classes.