Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JVM Timezone is not same as system timezone  RSS feed

 
J john
Greenhorn
Posts: 9
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am running java application in Linux box. The timezone of the system is set to CDT (ie. when I issue the command 'date' in terminal it display output like this 'Wed Aug 21 06:38:27 CDT 2013' ). But the java application is having timezone set to GMT. This is causing a 5 hrs difference in time java use and actual system time. How can I have jvm use the same time as the system.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J john wrote:I am running java application in Linux box. The timezone of the system is set to CDT (ie. when I issue the command 'date' in terminal it display output like this 'Wed Aug 21 06:38:27 CDT 2013' ). But the java application is having timezone set to GMT. This is causing a 5 hrs difference in time java use and actual system time. How can I have jvm use the same time as the system.

I think you need to show us your actual code since, in general, Java does use the system's local timezone.

For example: what does:
System.out.println( TimeZone.getDefault().getDisplayName() );
display?

Winston
 
J john
Greenhorn
Posts: 9
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
When I executing 'date' command in the terminal it display the result like this

[fuel@H00170a ~]$ date
Wed Aug 21 05:19:59 CDT 2013



This is the code am using in Java file

System.out.println( "TIME-ZONE:" + TimeZone.getDefault() );
System.out.println("Date in Java " + new Date( ));


Output comes like below:

TIME-ZONE:sun.util.calendar.ZoneInfo[id="GMT",offset=0,dstSavings=0,useDaylight=false,transitions=0,lastRule=null]
Date in Java Wed Aug 21 10:59:48 GMT 2013.


System date shows time as Wed Aug 21 05:19:59 CDT 2013 where as the time in java is Wed Aug 21 10:59:48 GMT 2013.

What needs to be done for java to time same as system date ie, Wed Aug 21 05:19:59 CDT 2013.

Some more information related to my environment.
The java application is running on a dump client. When the dump client boots up, it download OS, jre and all related software required to run the application from a Linux server machine using tftboot. The dump client does not have a connectivity to time server. So we use a program which will fetch time from the server machine and set that time to local machine before the tftboot installs jre on the client machine. Why we setting the time from server machine is because the dump client was initializing with wrong time and date. The year in the date was 2001.
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java -Duser.timezone=...etc...
 
J john
Greenhorn
Posts: 9
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. I am not passing any VM parameters to set the time zone. I can not pass timezone in VM parameter, since it will fail when daylight saving changes. Correct me if am wrong..
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Timezones can (and many do) cover daylight saving time changes.
 
J john
Greenhorn
Posts: 9
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you please suggest a solution?
 
Richard Tookey
Bartender
Posts: 1166
17
Java Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J john wrote:Could you please suggest a solution?


I thought Ivan had done so by showing how to use the command line JVM time zone parameter ! Have you tried it?
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can lead a horse to a river but can not make it drink.
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A further exercise is to find the Java time zone equivalent of CDT.
 
J john
Greenhorn
Posts: 9
Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Richard, I have tried that already. but not working.

Ivan, Thanks for the suggestion. But the issue i am talking about the jvm. Why JVM not taking system time. How can make jvm time uses system time by NOT using anything via code. Hope you understood what i meant.

regards
John
 
Ivan Jozsef Balazs
Rancher
Posts: 999
5
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Timezone Updater Tool
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!