Can I safely use DateTime.Now for specific things?

olimatt

Citizen
Jul 30, 2020
12
0
1
I have a LastRestock option for player vendors but if I use DateTime.UtcNow it's going to really mess with everyone's perception of when the vendor was last restocked. Is it safe to use the standard DateTime.Now for something like this or is it better to just use UtcNow for everything?
 

GoldDraco13

Squire
Aug 1, 2014
468
285
63
48
Canada
mycy4.com
Donate
Donate money to this user

DateTime.UtcNow tells you the date and time as it would be in Coordinated Universal Time, which is also called the Greenwich Mean Time time zone - basically like it would be if you were in London England, but not during the summer. DateTime.Now gives the date and time as it would appear to someone in your current locale.

I'd recommend using DateTime.Now whenever you're displaying a date to a human being - that way they're comfortable with the value they see - it's something that they can easily compare to what they see on their watch or clock. Use DateTime.UtcNow when you want to store dates or use them for later calculations that way (in a client-server model) your calculations don't become confused by clients in different time zones from your server or from each other.
 

Grimoric

Squire
Mar 21, 2015
219
74
28
45
DateTime.Now is 10 times slower then DateTime.UtcNow and should not be avoided in heavy calculations.
DateTime.Now uses DST and can cause a program to crash or return unwanted results while used at the daylight saving time event.
DateTime.Now uses UtcNow value in the first line in the function.

-Grim

If you are interested in how it works:

DateTime Now

DateTime UtcNow
Post automatically merged:

DateTime.Now is 10 times slower then DateTime.UtcNow and should not be avoided in heavy calculations.

I meant to write that is should be avoided. :D
 
Last edited: