Javascript Lambda时刻utc时间设置小时和分钟
当我在us-east-1中托管的AWS lambda中运行以下命令时Javascript Lambda时刻utc时间设置小时和分钟,javascript,aws-lambda,momentjs,Javascript,Aws Lambda,Momentjs,当我在us-east-1中托管的AWS lambda中运行以下命令时 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 curre
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的本地机器上运行此代码时,它会打印出来
2018年9月26日星期三19:24:00 GMT-0400(东部夏令时)
为什么单独在lambda中运行时会有4小时的差异?因为
新日期
采用本地时间戳,所以它返回UTC 19:07时的时间,即15:07。这与AWS不同,因为AWS可能不使用时区偏移,因此服务器的行为就好像在UTC中一样
您可能需要使用
Date.UTC
那么@jonaswillms如何告诉lambda在指定时区内的行为呢?