Reputation: 111
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?
Upvotes: 8
Views: 27579
Reputation: 1951
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.
Upvotes: 12