File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Java in General
Bookmark "Time difference" Watch "Time difference" New topic

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.


Paul Sturrock

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: 15080

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 8 API documentation
I agree. Here's the link:
subject: Time difference
jQuery in Action, 3rd edition