tags:

views:

94

answers:

2

Hi, I have a program that posts Datetime.Now(), but my coworkers computer's DateTime.Now() is off by an hour.

He changed it in his windows Date and Time Properties, but he is still posting a DateTime.Now() that is an hour off.

How can I fix this on his box without making modifications to my program (I have too many projects going on and need a quick fix for now)

+8  A: 

Is he in the correct time zone? Better use DateTimeOffset.

Flo
I will check. Would this make a difference?
Soo
Yes. It's quite likely something like daylight savings time, if not the time zone as such.
Steven Sudit
Does DateTime.Now change only when you restart the program? I think this is what was causing the problem.
Soo
No, it changes each time you call it (unless you call so frequently that not enough time has passed to make any difference to its value).
Steven Sudit
@Steven, then I'm completely stumped. My coworker's timezone and daylight savings settings were all fine, and his time is fine too. This is really bugging me out! :S
Soo
@Soo: So the time shown in the bottom right corner of his screen is correct, and the time zone and DST are correct, but `DateTime.Now` differs from yours?
Steven Sudit
@Steven: Yes, I saw it with my own eyes on his computer, I'm stumped.
Soo
@Soo: Obvious follow-up question, given Hans' response: Does his `DateTime.UtcNow` differ?
Steven Sudit
+2  A: 

Ask him to enable daylight savings time observance and to verify the timezone. And in general use DateTime.UtcNow. Ask more questions about it at superuser.com

Hans Passant
Yes, I will implement UtcNow with the next release of my program :)
Soo
Using UTC is a very good idea, particularly in a distributed system. It does mean that, in some cases, you will need to convert to the user's time zone for presentation purposes, but that's worth the trouble.
Steven Sudit
Definitely, the conversion is pretty simple too. The posting time is having a negative effect on how the program works, so I agree, it definitely will be worth the trouble.
Soo