DateTime.Now giving incorrect time

17,541

You should use DateTime.UtcNow instead of DateTime.Now to avoid time zone issues (DateTime.Now uses the time zone of the server), then you can convert the UTC value to the user's time zone.

Share:
17,541
Paulie22
Author by

Paulie22

Updated on June 19, 2022

Comments

  • Paulie22
    Paulie22 almost 2 years

    I'm developing an application in Visual Studio using C#. When I create a new instance of an object I want to attach the current date and time to it. Using DateTime.Now the time is off by one hour.

    I presume its a time-zone or daylight saving issue. I tried calling System.Globalization.CultureInfo.CurrentCulture.ClearCachedData() right before DateTime.Now but got the same result. How do I resolve this?