locked
Date Time crash issue when not at London zone (Repro included) RRS feed

  • Question

  • All,

    I'm pretty sure this is probably my misunderstanding something, but I have a scenario where if a user runs some code and their PC is set to London (UTC+0) everything works fine.

    However if they change the system time zone to say Melbourne (UTC+10), then the same code crashes.

    I have a small project that illustrates this:

    http://sdrv.ms/1aV9nCR

    It seems like DateTime.MinValue returns something different in these time zones, but my interpretation was that MinValue was a constant.

    For my purposes I just needed a 'reasonable' default and have changed to DateTime.Now as a solution, but I would be very interested to understand why this happens if someone can explain it to me??

    Thanks for reading,

    Chris

    Friday, November 22, 2013 10:03 AM

Answers

  • Hi MrChris,

    The code fails because the date is outside the range which is "The UTC time represented when the offset is applied must be between year 0 and 10,000".

    DateTimeOffset(DateTime.MinValue) will fail on any computer with a timezone that is ahead of UTC and  DateTimeOffset(DateTime.MaxValue) will fail on any computer with a timezone that is behind UTC. Take a look at the exception description here:http://msdn.microsoft.com/en-us/library/bb337819.aspx

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Monday, November 25, 2013 5:57 AM
    Moderator