Convert DateTimes That Are Close To DayLight Saving Time?

I am working on software that runs reports for GPS devices running 24/7/365. Part of the report output requires that we convert our stored database times (stored in central standard time) to user timers (any requested time zone). Twice a year, we encounter a problem with DST when people run reports that start earlier and end after a time change. It does not work on one line:

return TimeZoneInfo.ConvertTime(dateToConvert, DatabaseTime, UserTime);

dateToConvertis DateTimesubject to conversion. DatabaseTimeand UserTimeare objects TimeZoneInfo. I am not doing anything complicated or complicated, but DateTimes along with DST time change errors exclude. For example, 3/10/2013 2:02:11 AMeven if it is β€œtransformed” from Central time to central time.

What is the best method for handling DateTimes when changing DST time?

+5
source share
4 answers

, , , , (, ). 3/10/2013 2:02:11 AM CDT == 3/10/2013 8:02:11 AM UTC == 3/10/2013 3:02:11 AM CDT... . , timeanddate.com , ( 5 ). .NET- , , dev.

# 1:

, :

using System;

namespace TimeZoneSample
{
    public static class Program
    {
        public static void Main()
        {
            DateTime t = DateTime.Parse("3/10/2013 2:02:11 AM");
            Console.WriteLine(t);
            Console.WriteLine(t.ToUniversalTime());
            Console.WriteLine(t.ToUniversalTime().ToLocalTime());
        }
    }
}

:

3/10/2013 2:02:11 AM
3/10/2013 8:02:11 AM
3/10/2013 3:02:11 AM

, . quod erat manifestrandum

+1

, 3/10/2012 2:02:11 . 1:59 3:00, ..NET .

, dbase. , , , , , . UTC, , , . UTC , . TimeZoneInfo, ConvertTimeFrom/ToUtc.

+4

. , GMT. GMT. , , , . , , , . , , .

+3

, - . , , .

There is a workaround to get you out of your current jam. Since this is only a missed hour during spring that will throw an exception, you can catch the exception and add an hour before the time before repeating the conversion.

+1
source

All Articles