Monday, February 7, 2011

Obtaining a Java Date object for a Specific Time Zone

I want to get a java.util.Date object that represents a specific time at a specific time zone. Say "23:59 Wednesday 16 Feb 2011 EST"

TimeZone tz = TimeZone.getTimeZone("US/Eastern");
Calendar cal = Calendar.getInstance( tz );
cal.set(Calendar.YEAR, 2011);
cal.set(Calendar.MONTH, Calendar.FEBRUARY);
cal.set(Calendar.DAY_OF_MONTH, 16);
cal.set(Calendar.AM_PM, Calendar.PM);
cal.set(Calendar.HOUR, 11);
cal.set(Calendar.MINUTE, 59);
// cal.getTime() returns the Date for 23:59pm 16 Feb 2011 EST


No comments:

Post a Comment