+13  A: 

I've found (from many years of bad experiences) that it's best to store dates and times as UTC and only convert them to local time when a user wants to view them.

In addition, let a user enter local times but convert them to UTC before storing.

This will save you all sorts of problems down the track, including trying to figure out what's going on when your applications are distributed across multiple time zones.

If you only get and store UTC times, then DST doesn't matter.

One particularly nasty application we inherited sent messages with a local time with a timezone across timezones, requiring a great deal of energy to be expended on modifying these frequently.

When we modified it to only use UTC, it was much better. Conversion to UTC at one end was done as early as possible, conversion to local time was deferred until the last possible instant. The code got a lot smaller and a lot faster.

paxdiablo
Amen and +1 to this, bro'. One doesn't quite appreciate the genius of storing time as a `long` until one has had a fair share of timezone issues :)
gustafc
One caveat: On the day DST begins/ends it is impossible to determine the time a user meant if it is the repeating/vanishing hour. You either have to prompt the user or better yet... whenever possible don't depend on the user to enter a time, rather poll the system for the time.
codeelegance
Users should be home snug in bed when the switchover occurs :-)
paxdiablo
I agree. Storing time in _universal_ time removes any need for figuring out offsets, zones, display issues, etc, on the data side.
matt b
@Pax: Users, yes. System agents, not really. Example: "[02:15] Target temperature reached, run task #1234 in 60 minutes." I'm sure that was a tongue-in-cheek remark, but some people tend to desperately search for it-won't-happen-here excuses.
Piskvor
Yes, it's best to _store_ times in UTC (or at least sone non-DST time zone), but this isn't the question.
David Easley
+5  A: 

There are no reasons to forbid DST on the server, as time zones are (or should I say "should be") little more than formatting. The system clock is time-zone agnostic. Timestamps should be stored in an unambiguous format, either as "ticks since epoch" like System.currentTimeMillis() and its ilk (which are timezone-agnostic), or as text with the UTC offset specified (which then becomes unambiguous, like ISO 8601).

gustafc
UNIX/C-style timestamps in general, whether they're measured in seconds or milliseconds, are measured from January 1, 1970 00:00:00 UTC.
R. Bemrose
It seems that if (in my Java web-app) I call TimeZone.setDefault(TimeZone.getTimeZone("GMT")) then it's just as if the server itself were set to GMT. Ideal!
David Easley
A: 

As long as you use the built-in Java classes to store dates and times, DST shouldn't be an issue. The internal representation of time is "milliseconds past midnight, Jan 1, 1970, at Greenwich England", so what time zone you're in or whether DST is in effect is irrelevant.

Don't ever ever ever try to compare two dates or times using a text representation, like "10/09/2009" or whatever. Use the long millisecond value. I'm working on a system now where the original authors seem to use a different method every time they want to compare two dates. In one place they express the date as yyyy/mm/dd, then strip out the slashes, convert the result to an integer -- so 10/08/2009 becomes 20,091,008 -- and then compare those against each other. Other times they compare them as text strings. Etc. This gives incorrect results all over the place when multiple time zones or DST are involved.

Jay