ladookie
ladookie

Reputation: 1371

json date returned from wcf service not consistent

I have a service that returns a date. The weird thing is that most of the time it comes back like this: /Date(1364227320000)/

but sometimes it returns the date like this /Date(1364050020139-0400)/

when I open up the visual studio debugger, the dates look the same for each one (minus differences in time)

What could account for this difference?

Upvotes: 1

Views: 330

Answers (2)

carlosfigueira
carlosfigueira

Reputation: 87218

It depends on the kind of the DateTime object (i.e., the value of its Kind property). If you're returning a DateTime with DateTimeKind.Utc, there will be no offset. If the date time is of kind Local or Unspecified, the offset will be written out.

You can find more information about the format in the "DateTime Wire Format" section of the "Stand-Alone JSON Serialization" page on MSDN.

Upvotes: 1

Pete
Pete

Reputation: 6723

This is handled in System.Runtime.Serialization.Json.JsonWriterDelegator.WriteDateTimeInDefaultFormat(). If the DateTimeKind is Unspecified or Local, it adds the UtcOffset to the end (the -400 part, meaning Utc - 4 hours).

Upvotes: 2

Related Questions