C# 在数千行上执行转换时区。随机得到"The supplied DateTime represents an invalid time."

C# doing a convert timezone on thousands of rows. Randomly got "The supplied DateTime represents an invalid time."

我很困惑,只是一个简短的问题。我有一些代码循环遍历 ssis 包中的数据行以转换时区,但它连续失败,我不知道为什么。

完整的错误信息是:

The supplied DateTime represents an invalid time. For example, when the clock is adjusted forward, any time in the period that is skipped is invalid.

我运行做转换时间的代码是:

    DateTime easternstandardtime = Row.UniversalTime;

    TimeZoneInfo timeZoneGMT = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
    TimeZoneInfo timeZoneEST = TimeZoneInfo.FindSystemTimeZoneById("Eastern Standard Time");

    easternstandardtime = TimeZoneInfo.ConvertTime(Row.UniversalTime, timeZoneGMT, timeZoneEST);

    Row.StandardEasternTime = easternstandardtime;

代码在倒数第二行(转换时间)失败。 Row.UniversalTime 的值为 3/27/2016 1:10:03 AM。这怎么不行?变量的完整统计信息如下。令我感到奇怪的是,文件的其余部分都处理得很好,而且日期时间都相似。不知道为什么它会随机爆炸这样的值。有什么想法吗?

完整的 var 统计数据:

?Row.UniversalTime
{3/27/2016 1:10:03 AM}
Date: {3/27/2016 12:00:00 AM}
Day: 27
DayOfWeek: Sunday
DayOfYear: 87
Hour: 1
Kind: Unspecified
Millisecond: 0
Minute: 10
Month: 3
Second: 3
Ticks: 635946378030000000
TimeOfDay: {01:10:03}
Year: 2016

正如错误消息 有点 所暗示的,您正在尝试在实际上不存在的时间进行转换。

http://www.timeanddate.com/news/time/europe-starts-dst-2016.html

Most countries in Europe will spring forward 1 hour at 01:00 UTC

因此,如果大多数欧洲国家 spring 在 01:00(格林威治标准时间)前进,而您正在尝试转换 01:10 的格林威治标准时间,那么该时间实际上并不根据 DST 调整存在。看来这是你的问题。