Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Time difference

 
Prashanth Bhanu
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you post the code you are having trouble with?
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15490
43
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic