Lambda 时刻 UTC 时间设置小时和分钟



当我在托管在us-east-1中的AWSlambda中运行时

const currentTime = moment().utc().valueOf();
console.log(new Date( currentTime ));//1538003255995
Prints: Wed Sep 26 2018 19:07:35 GMT-0400 (Eastern Daylight Time) --- Correct in terms of current time.
const currentExecution = moment().set({
hour: 19,
minute: 24,
second: 0
}).utc().valueOf();
console.log(new Date( currentTime ));//1537989840995
Prints:Wed Sep 26 2018 15:24:00 GMT-0400 (Eastern Daylight Time)

为什么它显示 15:24 而不是 19:24? 但是当我在位于 EST 的本地机器上运行此代码时,它会打印Wed Sep 26 2018 19:24:00 GMT-0400 (Eastern Daylight Time)

为什么单独在 lambda 中运行时有 4 小时的差异?

因为new Date采用本地时间戳,所以它会返回您在 UTC 时 19:07 时所在位置的时间,即 15:07。这与AWS不同,因为它们可能不使用时区偏移量,因此服务器的行为就像

UTC一样您可能想使用Date.UTC...转到

最新更新