Javascript 无法使用从矩(无效日期)生成的unix时间戳初始化矩实例
我对这两个代码示例感到困惑 假设我们有一个从时刻生成的Unix时间戳Javascript 无法使用从矩(无效日期)生成的unix时间戳初始化矩实例,javascript,momentjs,Javascript,Momentjs,我对这两个代码示例感到困惑 假设我们有一个从时刻生成的Unix时间戳 moment().format('x'); Result: 1441721685361 代码片段1 moment(1441721685361); Result: moment object with date Tue Sep 08 2015 15:14:45 GMT+0100 (BST) 代码片段2 moment(moment().format('x')); Result: Invalid date 如果矩().f
moment().format('x');
Result: 1441721685361
代码片段1
moment(1441721685361);
Result: moment object with date Tue Sep 08 2015 15:14:45 GMT+0100 (BST)
代码片段2
moment(moment().format('x'));
Result: Invalid date
如果矩().format('x')返回一个整数,为什么我不能在矩()中使用它?矩().format('x')
返回字符串,在传递时间戳时,可以将字符串转换为数字(在前面添加+
,或者使用数字(字符串)
)并传递给矩,如下所示
console.log(typeof moment().format('x');
log(矩(+矩().format('x'))代码>
Facepalm。这是漫长的一天。。。好地方!