0

I am trying to figure this strange behaviour on a client machine (IE10)

When we create a new javascript Object, the ajax response from the server is \/Date(-62135596800000)\/.

I format the JSON Date in the following way:

var date = new moment(parseInt(response.substr(6)));

On the Client machine this Date Object returns the following Date Format 0000-12-31.

When I try to validate the Date on the Server I get the response is an error saying that this is not a valid date.

My validation is Fluent Validation and the Rule is

RuleFor(x=>x.LastUpdateDate).NotEmpty(); 

Can anyone point me in the correct direction to help solve this issue?

5
  • You're creating a date from the timestamp -62135596800000, a negative number. It's therefore giving you a date that's that many milliseconds before the beginning of the epoch. If I were you I'd fix the server so that it produced a less bizarre date format. Commented Dec 2, 2014 at 17:07
  • That is how JSON Serialiser in .NET serialises dates. The Project is too large currently to change the default one. Commented Dec 2, 2014 at 17:12
  • OK well whatever. If it's predictable then I guess it works. Anyway the root problem is that your timestamp actually is for a date in the year 0 CE. Commented Dec 2, 2014 at 17:15
  • But it actually isnt as easy as that. on most machines it shows as the .NET DateTime.Min of 0001-01-01 only on some machines is it 1 day before. Commented Dec 2, 2014 at 17:16
  • That's because different machines are in different time zones. A timestamp value is always interpreted as being relative to a fixed UTC reference time, but when you look at a JavaScript date, you get the date in local time (unless you use the UTC APIs available on the Date prototype). (added this as an answer) Commented Dec 2, 2014 at 17:20

1 Answer 1

1

Your timestamp value is interpreted as being an offset from a fixed UTC reference point. However, when you do something like

alert(theDate) 

you'll see the default rendition of the Date instance as it would appear in the local time zone. In other words, a computer in Hong Kong will show the same UTC date differently than a computer in London.

You can use

alert(theDate.toUTCString()) 

to see a UTC version of the date.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks @Pointy that would make alot of sense in the terms of what is happening on the App.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.