【发布时间】:2012-05-09 00:53:54
【问题描述】:
我是否错误地实现了 setUTCMilliseconds?我输入的任何值的日期都不正确。这只是错误值的一个示例。我所有的测试数据在 JS 中解析到 5 月 24 日(从现在开始的未来),但在 C# 中或使用快速在线转换工具时,我的 UTS MS 是正确的。
有什么想法吗?
function parseDate(epoch) {
var d = new Date();
//tried this too, but it shows me the actual epoch 1970 date instead
//var d = new Date(0);
//EDIT: this should be seconds in combination with Date(0)
d.setUTCMilliseconds(parseInt(epoch));
return d.toString();
}
// 1336423503 -> Should be Mon May 07 2012 13:45:03 GMT-7
// javascript says
Thu May 24 2012 05:03:21 GMT-0700 (Pacific Daylight Time)
【问题讨论】:
-
您传递的值不是一个纪元,而是一个自纪元的时间。
-
是的,我明白这个数字的含义。我在这里像epochtime一样使用它
标签: javascript date utc milliseconds