DateTime.Now vs system time

Viewed 4837

Let's imagine that this little program runs:

while (true)
{
    Console.WriteLine($"{DateTime.UtcNow} -> {DateTime.Now} tz={TimeZone.CurrentTimeZone.StandardName} / {TimeZoneInfo.Local.StandardName}");
    await Task.Delay(TimeSpan.FromSeconds(1));
}

When I change the system's time zone when the program is running the app does not see the change. The timezone and the time is as if the timezone has not changed.

In order for the app to display the new time and time zone I need to restart the app.

If I change the system time the time change is picked up immediately.

It would be great if you could help me with three questions:

  • is this documented anywhere?
  • why isn't the timezone change picked up while the application is running?
  • can I do anything so that the app picks up timezone changes while it's running?

Here's a little screenshot to show the .NET app using time different than the operating system: .NET App out of sync with system time.

BTW. On Windows IOT on Raspberry Pi, my experiment shows that if I restart the app it will show the new timezone, but the 'old' time. The new time will be picked up after restarting the the system.

1 Answers
Related