wood burning stoves 2.0*
The moose likes Java in General and the fly likes TimeZone Conversion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "TimeZone Conversion" Watch "TimeZone Conversion" New topic
Author

TimeZone Conversion

sushil java
Greenhorn

Joined: Oct 09, 2006
Posts: 9
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.


Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14272
    
  21

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


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
Jeremy James Brown
Greenhorn

Joined: Mar 24, 2011
Posts: 27
"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!
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: TimeZone Conversion