AWS lambda的差异应为3,获得19097

发布于 2025-01-21 09:59:56 字数 909 浏览 0 评论 0原文

然后最终将其汇合到最近的数字,因此12.8天为13。

我有一个AWS lambda函数,其中一部分计算上一个日期和今天日期之间的差异,调整为代表天数, 任何人都知道lambda是否具有表示date()函数的某些不同方法,因为在登录过程中的各个步骤后,我会返回一些怪异的值,因此我的函数不起作用。这是一些代码:

const today = new Date();
let item = {lasetReceiptCreated: '2022-04-11T20:00:22.549Z'};

let lastReceiptCreated = new Date(item.lasetReceiptCreated);
let dateDiff = today.getTime(); - lastReceiptCreated.getTime();
let diffInDays = Math.round(dateDiff / (1000 * 3600 * 24));

console.log('SkipDayCalc: ','\ndiff: ',diffInDays,'\ntoday.getTime: ',today.getTime(),'\nreceipt.getTime(): ',lastReceiptCreated.getTime());

结果日志显示了这一点:

SkipDayCalc:  
diff:  19097 
today.getTime:  1649963123100 
receipt.getTime():  1649707222549

那么为什么我的diffindays值返回为19097?当我在节点沙盒中运行时,我将获得具有相同代码的正确值。

I have a AWS lambda function, part of which computes the difference between a previous date and todays date, adjusts to represent as days and then finally rounds this to the nearest number, so 12.8 days for example will be 13.

I'm wondering if anyone knows if Lambda has some different way of representing Date() functions, because upon logging the results of various steps in the process I'm getting some weird values returned and hence my function isn't working. Here's some code:

const today = new Date();
let item = {lasetReceiptCreated: '2022-04-11T20:00:22.549Z'};

let lastReceiptCreated = new Date(item.lasetReceiptCreated);
let dateDiff = today.getTime(); - lastReceiptCreated.getTime();
let diffInDays = Math.round(dateDiff / (1000 * 3600 * 24));

console.log('SkipDayCalc: ','\ndiff: ',diffInDays,'\ntoday.getTime: ',today.getTime(),'\nreceipt.getTime(): ',lastReceiptCreated.getTime());

The resulting log shows this:

SkipDayCalc:  
diff:  19097 
today.getTime:  1649963123100 
receipt.getTime():  1649707222549

So why is my diffInDays value returning as 19097? When I run in a node sandbox I'm getting the correct value with the same exact code.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文