Google App脚本在日期中添加一天 [英] Google App Script Adding one Day to a date

查看:73
本文介绍了Google App脚本在日期中添加一天的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何在Google App脚本中为日期添加一天。我有这个脚本:

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

我不明白为什么

推荐答案

将其更改为:

var testDate = new Date();
var secondDate = new Date();
secondDate.setDate(testDate.getDate()+1);

这应该使白天对夏时制和and年都有好处。

This should keep the day good for daylight savings time changes and leap year as well.

这篇关于Google App脚本在日期中添加一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆