• 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
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Set TimeZone (to PST)

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