Flex Date() 构造函数错误转换 Unix 时间戳 argh
这真是要了我的命。 我正在尝试将 Unix 时间戳(1236268800,相当于 2009 年 3 月 5 日星期四 16:00:00 GMT)转换为 Flex 中的 Date 对象。
var timestamp:Number = 1236268800;
trace(new Date(timestamp));
Output: Wed Jan 14 23:24:28 GMT-0800 1970
还尝试了这个:
var timestamp:Number = 1236268800;
var date:Date = new Date;
date.time = timestamp;
trace(date);
Output: Wed Jan 14 23:24:28 GMT-0800 1970
这些方法中的任何一个都应该有效。 我在这里做错了什么?
This is seriously killing me. I'm trying to convert a Unix timestamp (1236268800, which equates to Thu, 05 Mar 2009 16:00:00 GMT) to a Date object in Flex.
var timestamp:Number = 1236268800;
trace(new Date(timestamp));
Output: Wed Jan 14 23:24:28 GMT-0800 1970
Also tried this:
var timestamp:Number = 1236268800;
var date:Date = new Date;
date.time = timestamp;
trace(date);
Output: Wed Jan 14 23:24:28 GMT-0800 1970
Either of those methods should work. What am I doing wrong here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
由于它被解析为毫秒,只需将纪元值乘以 1000:
Since it's parsed as milliseconds, just multiply the epoch value by 1000:
在 AS3 中,Date() 构造函数采用以毫秒为单位的值,而 Unix 时间以秒为单位。 尝试这个:
In AS3, the Date() constructor takes a value in milliseconds, whereas Unix time is in seconds. Try this:
你必须转换成毫秒,乘以 1000
you have to convert to milliseconds, multiply that by 1000
http://livedocs.adobe.com/flex/2/ langref/Date.html#Date()
如果传递一个数据类型为 Number 的参数,则会根据自 1970 年 1 月 1 日以来的毫秒数为 Date 对象分配一个时间值 0 :00:000 GMT,由唯一参数指定。
您需要将您的数字乘以 1000。
http://livedocs.adobe.com/flex/2/langref/Date.html#Date()
If you pass one argument of data type Number, the Date object is assigned a time value based on the number of milliseconds since January 1, 1970 0:00:000 GMT, as specified by the lone argument.
You need to multiply your number by 1000.