Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JAVA TimeZone issue EDT Vs EST

Tags:

java

timezone

dst

I a newbie to java and hence haven't been able figure this out since quite some time.

I am using Windows XP and the machine is set to TimeZone: Eastern Time (US & Canada).

I have a Java application, which takes the current system time and timezone info and writes a string like: 20101012 15:56:00 EST, to a file.

The last piece of Date above, i.e.: the timezone, changes from EST to EDT as i change my system date.

Being precise: From November(eg: Nov2009) to March (Mar 2010), it is EST, otherwise EDT.

EST is what I want ALWAYS and not EDT.

Is there any particular class / function, by which I can always read it as EST?

Awaiting for response.


Thanks for your replies. Well, I forgot to mention a few things.

  1. I want my machine to be set to: Eastern Time (US & Canada) in the windows time zone settings.

  2. In simple terms, What i want to do is: get my machine time, and write it to a text file

  3. I am aware of the daylight saving which happens from March to Nov.

But the problem is, when I write my machine time to the file, it is written as 2010 01 12 15:56:00 EST if daylight saving (DST) is not present and as 20101012 15:56:00 EDT, if DST is present. My concern is, whether it is DST or not, I want to write EST always.

like image 214
ViV Avatar asked Oct 14 '10 13:10

ViV


2 Answers

I don't think you should do what you are suggesting.

You are saying that regardless of what your system timezone is currently (Eastern Time is NOT your time zone, but UTC+5 or +4 is), you want it to display EST. This is just plainly wrong. Suppose it's in the summer, and your computer thinks it's 2010/6/15 15:00 locally. You print the current time and you get:

The time I print this out at: 2010 06 15 15:00:00 EDT

For whatever reason, you think that the EDT is unpleasing, and so you change it to EST:

I print this out at: 2010 06 15 15:00:00 EST

however, if you then send that snippet to someone else within the next hour, they'll be forced to think you traveled from the future! Since 15:00:00 EST is 16:00:00 EDT.

like image 126
Mike Axiak Avatar answered Nov 12 '22 01:11

Mike Axiak


I would create a custom zone:

TimeZone alwaysEst = TimeZone.getTimeZone("EST+5");

That will report as EST and will always be 5 hours ahead of UTC. In particular, do not choose an existing timezone or you will eventually get burned when a zone update changes the definition.

Do be aware that by forcing EST the dates you log will only match the time displayed by the system for 5 months out of the year. The other 7 months you'll be an hour off. It may simplify parsing the file, but it will confuse users.

like image 40
Devon_C_Miller Avatar answered Nov 12 '22 00:11

Devon_C_Miller