简体   繁体   English

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

[英]Lambda moment utc time set hours and minutes

When i run the following in a AWS lambda hosted in us-east-1当我在 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 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)

Why is it showing 15:24 instead of 19:24?为什么显示 15:24 而不是 19:24? But when i run this code in my local machine located in EST it prints Wed Sep 26 2018 19:24:00 GMT-0400 (Eastern Daylight Time)但是当我在位于 EST 的本地机器上运行此代码时,它会打印Wed Sep 26 2018 19:24:00 GMT-0400 (Eastern Daylight Time)

Why is there a 4 hr difference when run in lambda alone?为什么单独在 lambda 中运行时会有 4 小时的差异?

Because new Date takes the local timestamp, so it returns the time at the place where you were when it was 19:07 at UTC, which is 15:07 .因为new Date采用本地时间戳,所以它返回UTC 时间 19:07 时您所在位置的时间,即 15:07 Thats different with AWS as they probably use no timezone offset, so the server behaves as if it was in UTC这与 AWS 不同,因为它们可能不使用时区偏移,因此服务器的行为就像在 UTC 中一样

You might want to use Date.UTC ... goto您可能想使用Date.UTC ... goto

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM