Exception calling when TimeZoneInfo.ConvertTimeToUtc for certain DateTime values

前端 未结 2 918

When I run the code for this specific value of dt, an exception is thrown when I call the ConvertTimeToUtc Method. My local Machine timeZoneId is \"GMT Standard Time\"

2条回答
  •  执念已碎
    2020-12-29 23:14

    One can test whether the time in question is invalid using

    TimeZoneInfo.IsInvalidTime
    

    or if it is ambiguous using

    TimeZoneInfo.IsAmbiguousTime
    

    If it is ambiguous, an array of times that could apply can be retrieved from

    TimeZoneInfo GetAmbiguousTimeOffsets
    

    In the case of an interactive application, the user can be prompted for clarification.

    The BCL team wrote a good blog about the topic

    https://docs.microsoft.com/en-au/archive/blogs/bclteam/system-timezoneinfo-working-with-ambiguous-and-invalid-points-in-time-josh-free

提交回复
热议问题