Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# DateTime.UtcNow is returning the wrong value

Tags:

c#

datetime

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

like image 270
André Luiz Avatar asked Mar 08 '23 15:03

André Luiz


1 Answers

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.

like image 155
Joe Phillips Avatar answered Mar 27 '23 13:03

Joe Phillips