gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 16:49:39 24 4
gpt4 key购买 nike

只是一个简短的问题,因为我感到困惑。我有一些代码循环遍历 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。这怎么不行?变量的完整统计信息如下。令我感到奇怪的是,文件的其余部分都处理得很好,而且日期时间都相似。不知道为什么它会随机爆炸这样的值。有什么想法吗?

完整的变量统计:

?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

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

关于C# 在数千行上执行转换时区。随机得到 "The supplied DateTime represents an invalid time.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36266211/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com