Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

TimeZone Conversion

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please help to convert one timeZone to another.Given method is converting the given time to server Timezone where the server is located.But it is not converting from server time to any other user time.


 
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
Working with dates, times and timezones in Java can be confusing.

One thing that you need to be aware of is that class java.util.Date does not store information about timezones. A java.util.Date is a kind of fancy wrapper that stores a number of milliseconds since January 1, 1970, 00:00:00 GMT. So in a way you can regard a java.util.Date as always being in the GMT timezone.

A Calendar does have a TimeZone property, but setting or modifying it does not convert the date and time that the calendar holds to a different timezone.

When you convert a Date to a String by using a DateFormat object, then you can set the timezone on the DateFormat object, and it will convert your Date to a String that represents the date and time in that timezone. Likewise when you have a String that contains a Date and you use a DateFormat object to parse it. For example:

This prints out:

2006-11-28 15:45:12
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"A Calendar does have a TimeZone property, but setting or modifying it does not convert the date and time that the calendar holds to a different timezone."

Genius, pure genius!
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic