File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

TimeZone Conversion

 
sushil java
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • 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.


 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • 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
 
Jeremy James Brown
Greenhorn
Posts: 27
  • 0
  • Mark post as helpful
  • send pies
  • 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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic