formatDate() gives correct date -1 day (Google Apps Script)

断了今生、忘了曾经 提交于 2019-12-06 03:39:42

You are hardcoding the timezone in this line :

var Datename2 = Utilities.formatDate(newdate, "PST", "yyyy-MM-dd");

but this does not take into account the daylight saving and date only values in spreadsheets are always at 00:00:00 hours so one hour shift can change the date...

Replace with an automated value like this :

var Datename2 = Utilities.formatDate(newdate, Session.getScriptTimeZone(), "yyyy-MM-dd");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!