André Luiz
André Luiz

Reputation: 7312

C# DateTime.UtcNow is returning the wrong value

I'm having an issue that I'm having a hard time to figure out, which is the result of DateTime.UtcNow. In My local machine when I print it gives me the right time, but in my server it's 3 hours ahead. This is how I'm printing, in a Razor view:

<h1>@DateTime.UtcNow.ToString("yyyy-MM-dd HH:mm:ss")</h1>

What can I check to make this give me the right time?

Thanks for any help

Upvotes: 4

Views: 3494

Answers (1)

Joe Phillips
Joe Phillips

Reputation: 51200

Your server is set to the wrong time. Windows keeps the hardware clock set to local time so if the time is wrong in comparison to the timezone, that essentially means the system clock is not synchronized with UTC time.

If your timezone is set to Chicago timezone, the time on the system tray must also match Chicago time.

Upvotes: 7

Related Questions