Time showed wrong

Hi,

I use a Linux box. The system time is correct. When I use the following code I get a wrong result.

...

Timestamp currTime = new Timestamp (System.currentTimeMillis());

System.out.println(currTime);

...

The result is: 2007-06-0609:15:52.249 (-1 hour diff)

If I execute the date command from the system shell i get the correct value:

Wed Jun 610:16:50 EEST 2007

My system time zone is Bucharest/Europe.

How I can solve this?

Message was edited by:

mkeresztes

[557 byte] By [mkeresztesa] at [2007-11-27 6:33:33]
# 1
You should use Calendar and SimpleDateFormat to print times. Your Timestamp is probably showing UTC.
CeciNEstPasUnProgrammeura at 2007-7-12 17:59:28 > top of Java-index,Java Essentials,Java Programming...
# 2
What does the output look like for you?System.out.println(TimeZone.getDefault());
quittea at 2007-7-12 17:59:28 > top of Java-index,Java Essentials,Java Programming...
# 3
hmm, that would mean another problem somewhere.He's located at GMT+2 so should see a 2 hour difference to UTC (or 3 if he's using DST) :)
jwentinga at 2007-7-12 17:59:28 > top of Java-index,Java Essentials,Java Programming...
# 4
Hi the output is:sun.util.calendar.ZoneInfo[id="GMT+02:00",offset=7200000,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
mkeresztesa at 2007-7-12 17:59:28 > top of Java-index,Java Essentials,Java Programming...
# 5
Strange. And the output looks pretty short, I get a lot more information when I call it. What Java version do you use?
quittea at 2007-7-12 17:59:28 > top of Java-index,Java Essentials,Java Programming...
# 6
Hi,My java version is:java version "1.5.0_11"Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_11-b03)Java HotSpot(TM) Client VM (build 1.5.0_11-b03, mixed mode, sharing)
mkeresztesa at 2007-7-12 17:59:28 > top of Java-index,Java Essentials,Java Programming...
# 7
Wait a minute; you should be GMT+3 by now, cause it's summer time. Your timezone setting in Java is wrong. It should be something like ... offset=7200000, dstSavings=3600000,useDaylight=true ...
quittea at 2007-7-12 17:59:28 > top of Java-index,Java Essentials,Java Programming...
# 8
OK.But what I can do?I cannot hard code the timezone settings because my app is used by people from different time zones (USA, Europe, etc.)
mkeresztesa at 2007-7-12 17:59:28 > top of Java-index,Java Essentials,Java Programming...
# 9
Check the timezone settings and java installation of the Linux machine; Java should be able to detect the correct settings depending on the system default, so no need for a hardcoded time zone.
quittea at 2007-7-12 17:59:28 > top of Java-index,Java Essentials,Java Programming...
# 10
I linked manually the file /usr/share/zoneinfo/Europe/Bucharest to /etc/localtime and this solved my problem.
mkeresztesa at 2007-7-12 17:59:28 > top of Java-index,Java Essentials,Java Programming...