• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Daylight saving time

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I want to show some information to people who are in different time zones (for now say only in usa).

The information includes timestump that is in GMT. I want to show them in EST, EDT, PST, PDT and so on.

I can ask users to give their timezone. Then on, I want to automate the whole process of showing the time. I know the main part is just adding or subtracting the hour, but the problem comes with daylight saving time. How do I handle that?
I'm not expectating the code (even though a full function that takes GMT and a timezone and give back the time would be ideal), but some headstart would be appreciated.

Thanks in advanced.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You would use SimpleDateFormat to format a timestamp for human viewing. And if you have persuaded your users to give you a java.util.TimeZone object (maybe via a drop-down list) then you can call the SimpleDateFormat's setTimeZone() method with that time zone, and it will automatically format the date as if it were in that time zone. It takes care of daylight saving time and everything. You don't have to add any hours or minutes. So, it's only a few lines of code:
 
Mkhaya Tini
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cool.

Thanks a lot.
 
Mkhaya Tini
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


I'm having problem with this line.

for example, if I say



I get an error. Also, is the Date java.util.Date?

Thanks.
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, "Date" is java.util.Date. Naturally you can't assign a String to a Date variable. Use SimpleDateFormat to convert a String to a Date... as I already said in an earlier response in this same thread.
reply
    Bookmark Topic Watch Topic
  • New Topic