I'm having an issue with java timezones, if anyone can help me.
I have a web application running on tomcat 5.5 (not sure if this is relevant), with the following JVM version
[someuser@webserver bin]$ java -version
java version "1.5.0_06"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_06-b05)
Java HotSpot(TM) Server VM (build 1.5.0_06-b05, mixed mode)
[someuser@webserver bin]$
The system date is, say -
[someuser@webserver bin]$ date
Mon Aug 15 09:09:46 EST 2011
Within the web application, I make a call at a certain point to Calendar.getInstance().getTime()
, and I print this timestamp in the logs.
Problem is that this timestamp gets returned in EDT, although server's time is in EST. For this reason, the date returned is 1h later than it should.
What I want to achieve is make Calendar.getInstance().getTime()
to return a date in the same timezone as the system.
I have searched the forums, and found some suggestions that the jvm is not reading correctly the system's timezone.
I have tried starting the tomcat with -Duser.timezone=EST
parameter, but the system keeps returning timestamps in the EDT timezone. Please note - trying -Duser.timezone
with a non-est parameter seems to work.
The problems seems to be of a different nature.
My issue is somehow similar with this SO question. However, I'm only trying to get the date in the same timezone as the system is in, without any special handling.
Are you able to help?
If you cannot change the OS or the JVM timezone, you can still convert a Java Date/Time or Timestamp to a specific time zone using the following two JDBC methods: PreparedStatement#setTimestamp(int parameterIndex, Timestamp x, Calendar cal) – to convert the timestamp that goes to the database.
TimeZone represents a time zone offset, and also figures out daylight savings. Typically, you get a TimeZone using getDefault which creates a TimeZone based on the time zone where the program is running. For example, for a program running in Japan, getDefault creates a TimeZone object based on Japanese Standard Time.
UTC stands for Co-ordinated Universal Time. It is time standard and is commonly used across the world. All timezones are computed comparatively with UTC as offset.
I had the same issue. It turns out for me Java was looking in the /etc/sysconfig/clock
file not the /etc/localtime
file. This this for comment for more info
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