我想使用 momentjs 获得纪元秒数。
例如,现在的时间是2019-04-20T15:07:04.388Z
EST,我想以2019-04-19T00:00:00.000Z
UTC 获取昨天的开始时间纪元。
我试过下面的代码 -
const now = new Date();
const start = moment(now) // get current datetime
.utcOffset(0) // convert to UTC
.subtract(24, "hours") // go 24 hours into the past
.startOf("day") // get the start of the date we landed on
.unix(); // get unix timestamp
console.log(now);
console.log(start);
上述程序的输出是 -
Sat Apr 20 2019 15:11:23 GMT-0400 (EDT) {}
1555650000
根据https://www.unixtimestamp.com/index.php 1555650000 转换为Fri, 19 Apr 2019 05:00:00 +0000
. 但我希望它是Fri, 19 Apr 2019 00:00:00 +0000
UTC。
我们代码中使用的 momentjs 版本 -
"moment": "2.24.0",
"moment-timezone": "^0.5.23"
知道我怎么能得到这个吗?