jQuery in Action, 2nd edition*
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 Murach's Java Servlets and JSP this week in the Servlets 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: 14074
    
  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
 
 
subject: Time difference
 
Similar Threads
Convert Date from one timezone to another
Date serialization and timezones
How can I set timezone for Jboss server
TimeStamp.toString() does not work as expected
Regarding Synchronization