计算Google Apps脚本中两个日期之间的差异 [英] Calculating difference between two dates in Google Apps Script
本文介绍了计算Google Apps脚本中两个日期之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我从以下API调用获取日期时间 - :
I am getting datetime from an API call like following-:
2017-11-21T20:23:26 + 0000
现在我想将此与今天的日期进行比较并计算天数的差异,我该如何在谷歌应用程序脚本中这样做。
Now I want to compare this with today's date and calculate the difference in number of days, how can i do that in google apps script.
谢谢你的帮助。
推荐答案
我认为你可以这样做,
var dt1 = new Date(), // today's date
dt2 = new Date("2017-11-21T20:23:26+0000"); // your date from API
// get milliseconds
var t1 = dt1.getTime(),
t2 = dt2.getTime();
var diffInDays = Math.floor((t1-t2)/(24*3600*1000));
// 24*3600*1000 is milliseconds in a day
console.log(diffInDays);
这篇关于计算Google Apps脚本中两个日期之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文