Google App Script 将一天添加到日期 [英] Google App Script Adding one Day to a date
本文介绍了Google App Script 将一天添加到日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道如何在 Google App Script 中为日期添加一天.我有这个脚本:
I can't figure out how to add one day to a date in Google App Script. I have this script:
function dateTest() {
var testDate = new Date();
var secondDate = new Date(testDate.getDate()+1);
Logger.log(testDate);
Logger.log(secondDate);
}
产生以下日志:
[16-11-30 16:35:02:499 GMT] 2016 年 11 月 30 日星期三 16:35:02 GMT+00:00
[16-11-30 16:35:02:499 GMT] Wed Nov 30 16:35:02 GMT+00:00 2016
[16-11-30 16:35:02:500 GMT] 星期四 1 月 1 日 01:00:00 GMT+01:00 1970
[16-11-30 16:35:02:500 GMT] Thu Jan 01 01:00:00 GMT+01:00 1970
我不明白为什么它没有添加到日期?
I don't understand why it's not adding to the date?
推荐答案
改为:
var testDate = new Date();
var secondDate = new Date();
secondDate.setDate(testDate.getDate()+1);
这应该让这一天有利于夏令时的变化和闰年.
This should keep the day good for daylight savings time changes and leap year as well.
这篇关于Google App Script 将一天添加到日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文