• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

set JVM timezone in Linux

 
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I want to change my JVM's timezone from IST to SGT. My Operating System is Centos. Please guide me for this....
Thanks in advance.
 
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you think you need to do this? This does not really make sense so there is normally no need to do this. The class java.util.Date store the date as the number of milliseconds since 1/1/1970 00:00:00 UTC regardless of the platform timezone. The JVM uses the platform default timezone for converting java.util.Date to String or String to java.utll.Date but you should specify a timezone for these conversions when using SimpleDataFormat or java.utl.Calendar. This way your application will be correct regardless of the default platform timezone.
 
shital sonavane
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am saving date by converting it into long and while doing this i am getting problem. because when date is converted to long it is considers the timezone.
Therefor i want to change my systems timezone for data conversion according to SGT timezone.
 
James Sabre
Ranch Hand
Posts: 781
Netbeans IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

shital sonavane wrote:I am saving date by converting it into long and while doing this i am getting problem. because when date is converted to long it is considers the timezone.
Therefor i want to change my systems timezone for data conversion according to SGT timezone.




Sorry but I don't really understand. java.util.Date.getTime() provides the number of milliseconds since 1/1/1970 00:00:00 UTC. What use case requires a different epoch and/or time zone? If you have a valid use case then I still don't see the need to change the JVM time zone. What stops you creating methods to generate the milliseconds in the time zone you desire and convert back from this value to java.util.Date.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to parse or format dates using SimpleDateFormat, and you want to use a specific timezone to do that, then the simplest thing to do is to create the SimpleDateFormat object and then call its setTimeZone(TimeZone) method to set that specific timezone. You don't need to change the whole JVM.

You'll have to find the real name of the time zone, though, "SGT" isn't going to do.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Shital, can you show us the code that you are currently using to convert the date to a long?

As James and Paul have already mentioned, changing the timezone setting of your system is most likely not the right solution for the problem that you are having.
 
shital sonavane
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey guys thanks. i found the solution.
I did this using .
 
shital sonavane
Greenhorn
Posts: 24
Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the code i am using to convert date into long.

 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of setting the default timezone, you should set the timezone on the SimpleDateFormat object:

 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic