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.
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:
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.