Skip to content

DateTime.Now returns incorrect time on windows computer when time zone has changed #31043

Description

@WilliamSBunin

Issue Title

DateTime.Now returns incorrect time on windows computer when time zone has changed

General

Details

I was running a windows service created in C# when I noticed my computer was set to the wrong time zone. I switched it to the correct timezone and waited for my service to do something. It did not. I restarted the service and it worked correctly. I created a test app in C# and noticed that If I change my timezone, DateTime.Now does not use the updated time. I then created a test app in .NET Core to see if it had the same behavior, and it does.

.NET Core version

.NET Core 2.1

Operating System version

Windows 10 Pro - 1903 (18362.207)

Test Code

using System;

namespace DateTimeNowTest
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(DateTime.Now);
            Console.ReadLine();
            //Before pressing enter, change time zone
            Console.WriteLine(DateTime.Now);
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.DateTimeenhancementProduct code improvement that does NOT require public API changes/additions

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions