简体   繁体   English

如何将Oracle Date对象/ Long转换为javascript日期?

[英]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. 我正在查询一个Web服务,该服务从如下所示的Oracle数据库返回一个日期: /Date(1369519200000)/但我丝毫不知道Long的值表示什么,所以我不知道该怎么做。将其转换为javascript日期对象。

Please help 请帮忙

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. d现在为“ Sat May 25 2013 d.toUTCString() GMT”(通过d.toUTCString() ),希望听起来像您可能期望的那样。

This doesn't take timezones into account; 这没有考虑时区; if you know the date is UTC you can use setUTCMilliseconds instead, or just: 如果您知道日期为世界标准时间,则可以改用setUTCMilliseconds或:

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. 但是您可能需要确切地知道Web服务向您发送了什么信息,因此您知道自己正确地解释了日期-例如,是否需要应用时区或夏令时调整。

No idea about it's general reliability, but this article includes some info on data handling, including what the epoch date means. 不知道它的一般可靠性,但是本文包含有关数据处理的一些信息,包括时期的含义。

Looks like it's in number of milliseconds since the UNIX epoch (midnight 1970). 看起来距UNIX 纪元 (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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM