Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
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 Java 8 in Action this week in the Java 8 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: 13884
    
  10

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 7 API documentation
Scala Notes - My blog about Scala
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!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: TimeZone Conversion
 
Similar Threads
Date Formatting Help
current time problem on AIX
Java API - to get next year
TimeZones
What fields does java.util.Date.equals compare?