MushinNoShin
MushinNoShin

Reputation: 4886

asp.net datetime serialization returns different values on different servers

I'm retrieving a datetime from a shared database. More precisely I'm retrieving a timespan and converting it to a datetime via Convert.ToDateTime(timespan.ToString()). I have two servers which operate in two different time zones.

One returns the datetime as /Date(1402761600000)/ the other as /Date(1402776000000)/, that's a difference of 14400000, or 4 hours.

Just a hunch that this is somehow timezone related (as I'm at GMT -4).

Why are my times being returned differently? What can I do to prevent this?

Upvotes: 0

Views: 124

Answers (1)

Ben Foster
Ben Foster

Reputation: 34810

Convert.ToDateTime will return a local time which is why you are getting different results for servers in different time zones.

Try:

Convert.ToDateTime(ts.ToString()).ToUniversalTime();

Which will return the UTC time.

Upvotes: 1

Related Questions