Convert UTC DateTime to another Time Zone

The best way to do this is simply to use TimeZoneInfo.ConvertTimeFromUtc. // you said you had these already DateTime utc = new DateTime(2014, 6, 4, 12, 34, 0); TimeZoneInfo tzi = TimeZoneInfo.FindSystemTimeZoneById(“Pacific Standard Time”); // it’s a simple one-liner DateTime pacific = TimeZoneInfo.ConvertTimeFromUtc(utc, tzi); The only catch is that the incoming DateTime value may not … Read more

Best practices with saving datetime & timezone info in database when data is dependant on datetime

Hugo’s answer is mostly correct, but I’ll add a few key points: When you’re storing the customer’s time zone, do NOT store a numerical offset. As others have pointed out, the offset from UTC is only for a single point in time, and can easily change for DST and for other reasons. Instead, you should … Read more

.NET DateTime.Now returns incorrect time when time zone is changed

Yes, the current time zone is cached. For a good reason, it avoids trouble with broken code that uses DateTime.Now to implement elapsed time measurement. Such code tends to suffer a heart-attack when the time suddenly changes by an hour or more. You will have to call System.Globalization.CultureInfo.ClearCachedData() to reset the cached value. The next … Read more

Parsing of Ordered Timestamps in Local Time (to UTC) While Observing Daylight Saving Time

In C#: // Define the input values. string[] input = { “2013-11-03 00:45:00”, “2013-11-03 01:00:00”, “2013-11-03 01:15:00”, “2013-11-03 01:30:00”, “2013-11-03 01:45:00”, “2013-11-03 01:00:00”, “2013-11-03 01:15:00”, “2013-11-03 01:30:00”, “2013-11-03 01:45:00”, “2013-11-03 02:00:00”, }; // Get the time zone the input is meant to be interpreted in. TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById(“Eastern Standard Time”); // Create an array … Read more

Does UTC observe daylight saving time?

No, UTC itself never has DST. It is the constant frame of reference other time zones are expressed relative to. From the Wikipedia UTC page: UTC does not change with a change of seasons, but local time or civil time may change if a time zone jurisdiction observes daylight saving time or summer time. For … Read more

Determine Whether Daylight Savings Time (DST) is Active in Java for a Specified Date

This is the answer for the machine on which the question is being asked: TimeZone.getDefault().inDaylightTime( new Date() ); A server trying to figure this out for a client will need the client’s time zone. See @Powerlord answer for the reason why. For any particular TimeZone TimeZone.getTimeZone( “US/Alaska”).inDaylightTime( new Date() );

Is it always a good idea to store time in UTC or is this the case where storing in local time is better?

I think that in order to answer that question, we should think about the benefits of using UTC to store timestamps. I personally think that the main benefit to that is that the time is always (mostly) guaranteed to be consistent. In other words, whenever the timezone is changed, or DST applied, you don’t get … Read more