How different is EST from EST5EDT ? Isn't EST take into account DST?
I wrote a small java snippet to figure out the difference and output says EST5EDT takes in to account DST while EST does not
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss.SSS");
dateFormat.setTimeZone(TimeZone.getTimeZone("EST5EDT"));
System.out.println("EST5EDT" +dateFormat.format(new Date()));
/* prints EST5EDT2013-Apr-05 02:24:16.471 */
dateFormat = new SimpleDateFormat("yyyy-MMM-dd HH:mm:ss.SSS");
dateFormat.setTimeZone(TimeZone.getTimeZone("EST"));
System.out.println("EST "+dateFormat.format(new Date()));
/*prints EST 2013-Apr-05 01:24:16.472 */
But the below snippet produced shocking output
System.out.println("EST5EDT offset "+TimeZone.getTimeZone("EST5EDT").getRawOffset()/(60*60*1000));
/* prints 5 instead of 4 (DST) */
Could someone please explain what exactly is happening here ? why is getRawOffset returning 5 instead of 4 ? How to get timezone offset with DST?
Isn't EST take into account DST?
No. By Definition EST is "Eastern Standard Time" Or UTC-5:00.
EDT is "Eastern Daylight Time" Or UTC-4:00.
It's a bit confusing, because for example, New York switches between EST and EDT, and Seattle switches between PST and PDT.
Sometimes people will say incorrectly "I'll call you 1pm EST" when they actually mean to say, " I'll call you 1pm Eastern time" which properly takes into account whether or not it's Daylight Savings.
This wikipage has a little more information.
why is getRawOffset returning 5 instead of 4
Timezone.getRawOffset always returns the number of milliseconds for standard time, which is 5 * (60 * 60 * 1000)
Since the UTC Offset changes based of the day of the year (to account for DST), you'll need to use getOffset, and supply it the date you want to use.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With