Adding to this whole discussion... I work on a rather large scheduling app that has to work globally. We store all time in GMT and then convert it on the fly depending on the timezone and locale of the user accessing the app. For this, we use a few different java DateFormat's depending on what type of time we need to present either in the Session or in a ThreadLocal depending on the app being used (there are many different apps). We also have a few methods to do start of day and end of day as well.
The key for us is using GregorianCalendar for everything -- as soon as we need to do any sort of date math, we make a GregorianCalendar object out of the timestamp. Conversion between GMT and a local timezone is simple too :
/** * Returns a new time stamp for the passed in Timezone. * * @param iMillis time stamp to be converted * @param iZone Timzone in which conversion is needed. * @return an NSTimestamp with date converted to iZone. */ public static NSTimestamp changeDateForTimezone(long iMillis, TimeZone iZone) { long anOffset = 0l; if (iZone != null) anOffset = iZone.getOffset(iMillis); return new NSTimestamp(iMillis + anOffset); } public static NSTimestamp changeDateForTimezone(NSTimestamp iTimestamp, TimeZone iZone) { return changeDateForTimezone(iTimestamp.getTime(), iZone); }
If anyone needs more info on how we use time and timezones, please contact me.
Thanks, David. On Jan 3, 2008, at 11:50 AM, Andrew Lindesay wrote: Hello;
I jotted-up some notes about how I handle dates, timestamps and timezones that might be of interest in the context of this thread and mirrors Pierre's comment below. See section 0.5.21 in the following document;
cheers.
Because of this, storing any date in local time instead of GMT is likely to leads to disappointment. There is no guarantee that the time zone you used to store your date will be the same than the one you used to retrieve it. I fact there is a good possibility that this will have changed under your feet. Typically each revision of the JVM includes a new version of the time zone database. The only safe way of storing dates is GMT as this is by definition guaranteed not to change.
|