This week's book giveaway is in the Python forum.
We're giving away four copies of Python Continuous Integration and Delivery and have Moritz Lenz on-line!
See this thread for details.
Win a copy of Python Continuous Integration and Delivery this week in the Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Devaka Cooray
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Tim Holloway
  • Claude Moore
  • Stephan van Hulst
Bartenders:
  • Winston Gutkowski
  • Carey Brown
  • Frits Walraven

Set TimeZone (to PST)  RSS feed

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to convert a Calendar object from one timeZone to another and couldn't succeed. This is what I'm trying to do:



In the above code, the startDate is initially 1/27/06, 5.00 am GMT and I want this to be 1/27/06, 5.00 am PST (since the local time is PST), how ever it is not so. Any idea how to achieve this?

TIA
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sounds like the Calendar was set incorrectly to begin with. It seems preferable to fix it when it's created, rather than after it's been passed around to other components of your program. But maybe that's not possible. Well, you should be able to fix this by subtracting the time zone offset. The other thing is you may well need to tell the JVM what time zone to display results in - DateFormat (and SimpleDateFormat) are a good way to control this. Try something like this:
 
It will give me the powers of the gods. Not bad for a tiny ad:
Become a Java guru with IntelliJ IDEA
https://www.jetbrains.com/idea/
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!