Be careful with DST and such. I work for a company that tracks time (timecards, scheduling etc.). Handling DST properly is tricky.
The method Date.getTime() is timezone-less. It is a 'universal' time, a *timestamp*, just a time without a definition of place/location! It returns the number of milliseconds since midnight on 1/1/1970 UTC (=GMT without DST). Wherever you are, and assuming your device's clock is set properly, the Date.getTime() must return the same value, since it is timezone-less. However, if you want to know the *time-of-day* at your location, then you add a place/location to the universal time: What time-of-day is it where I am on the timestamp returned by Date.getTime()? The place/location is expressed in timezones. E.g. Date.getTime() returns 15:00 7/19/20098 GMT. I am in Boston, which is in timezone GMT-5. This means that the time-of-day in Boston is 10:00 7/19/2009 GMT-5:00. Note that timezones are not always in hours, then can even be in chunks of 15 minutes, e.g. 20:45 7/19/2009 GMT+5:45. On top of this, there are daylight saving laws/regulations (DST). Every region has its own laws regarding daylight saving. You can have multiple DST definitions in one timezone and they can change over the years. In the USA, then can vary per county, for example. The problem with DST is that you'll get non-existing time-of-days and double-counted time-of-days. E.g. in most countries, the DST changes at 2:00 am. When moving the clock forwards, the time-of-day 2:15am does not exist. What do you do if you get such input? When moving the clock backwards, the time-of-date 1:15am happens twice. Which one of the two do you choose if you get such input? In short: When dealing with timestamps, like the one returned by Date.getTime(), don't worry about timezones, DST, etc. When dealing with time-of-day, be careful. Try to figure out the corresponding timestamp and store this value. On Jul 19, 8:44 am, Cheng Zhong <[email protected]> wrote: > Hi all, > > What will Date.getTime() returns in a region with Daylight Saving Time > enabled? > > Does this function returns a DST time or not? > > I call Date.getTime() in a place with DST (such as U.S.), and convert > it to a local time in China (no DST), I get a wrong time (one hour > ahead of local time in China). How can I fixed this problem? > > Maybe I didn't tell tings clearly, but we don't use DST in China... I > don't understand DST very well. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

