File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Time difference Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Time difference" Watch "Time difference" New topic
Author

Time difference

Prashanth Bhanu
Ranch Hand

Joined: Sep 25, 2003
Posts: 110
Hi Friends,

I created two instances of Date(java.util.Date).I want to set different TimeZone for each instance.
I was able to set the time zone for each instances by using the GregorianCalendar class. However,when i set the timezone of the first instance the other instance's timezone also gets that value.Basically i dont want to disturb other instance value upon timezone change.
It seems that when you set the TimeZone,java treats it as one global static variable...Please help me to get away from this problem.Thanks in advance to all of you.

Thanks,

Prashanth
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

Can you post the code you are having trouble with?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

You cannot set a timezone on a Date object. A Date object represents a specific point in time, regardless of the timezone.

If you want to print a date and time in a specific timezone then use a DateFormat object to convert the Date object to a string; you can set the timezone on the DateFormat object. For example:


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Time difference