Win a copy of Learning OpenStack Networking: Build a solid foundation in virtual networking technologies for OpenStack-based clouds this week in the Cloud/Virtualization 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 ...
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Set TimeZone (to PST)  RSS feed

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

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?

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 is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!