
DateTime dt = DateTime.Parse("3/13/2016 2:41:00 AM");DateTime Date_Time = TimeZoneInfo.ConvertTimeBySystemTimeZoneID(dt,"Eastern Standard Time","GMT Standard Time");Response.Write(dt); 执行后,我收到此错误:
解决方法 尝试检查时间是否模糊或有效时间. Due to the daylight change你提到的时间,即2:41:00 AM不存在,因为时钟提前1小时,因此日期无效或含糊不清.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. Parameter name: dateTime
2016 Sun,13 Mar,02:00 CST → CDT +1 hour (DST start) UTC-5h Sun,6 Nov,02:00 CDT → CST -1 hour (DST end) UTC-6h
您也可以参考此博客:System.TimeZoneInfo: Working with Ambiguous and Invalid Points in Time
System.TimeZoneInfo (currently available as part of .NET Framework 3.5
Beta 1) contains methods for checking if a DateTime instance
represents an ambiguous or invalID time in a specific time zone. These
methods are particularly useful for valIDating user-supplIEd points in
time.Background information
Time zones that adjust their time for Daylight Saving Time (in most
cases by moving the clock time back or forward by 1 hour) have gaps
and repeats in the timeline — wherever the clock time was moved
forward or back by the adjustment. Let’s use Pacific Standard Time as
an example. In 2007 Pacific Standard Time (PST) changes to Pacific
Daylight Time (PDT) at 02:00AM (“spring forward”) on the second Sunday
in march and then returns at 02:00AM (“fall back”) on the first Sunday
in November
要检查时间是否有效,您可以使用:
TimeZoneInfo.IsInvalIDTime总结
以上是内存溢出为你收集整理的c# – DateTime解析错误:提供的DateTime表示无效时间全部内容,希望文章能够帮你解决c# – DateTime解析错误:提供的DateTime表示无效时间所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)