pythonian29033
pythonian29033

Reputation: 5207

How do I convert an Oracle Date object/Long into a javascript date?

I'm querying a web service that returns a date from an Oracle database that looks like this: /Date(1369519200000)/ but I haven't the slightest clue what the value of this Long represents, so I don't know how to convert it into a javascript date object.

Please help

Upvotes: 0

Views: 887

Answers (2)

Alex Poole
Alex Poole

Reputation: 191275

It looks like an epoch data in milliseconds:

var ms = 1369519200000;
var d = new Date(0);
d.setMilliseconds(ms);

d is now 'Sat May 25 2013 22:00:00 GMT' (via d.toUTCString()), which hopefully sounds about what you might expect.

This doesn't take timezones into account; if you know the date is UTC you can use setUTCMilliseconds instead, or just:

var d = new Date(ms);

But you probably need to know exactly what the web service is sending you so you know you're interpreting the date correctly - whether you need to apply timezone or daylight saving adjustments, for example.

No idea about it's general reliability, but this article includes some info on data handling, including what the epoch date means.

Upvotes: 3

Michael
Michael

Reputation: 58437

Looks like it's in number of milliseconds since the UNIX epoch (midnight 1970).

If you can get that value as an integer you could do something like this:

var dbDate = new Date(0);  // start out at  time 0, i.e. the unix epoch
dbDate.setUTCSeconds(millisSinceEpoch/1000);

Upvotes: 0

Related Questions