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

前端 未结 1 1401
野性不改
野性不改 2021-01-13 20:56

I\'m using a Google Spreadsheet to log some things on a day-to-day basis. To make it user-friendly to my colleagues I\'ve made the spreadsheet as \"interface-ish\" as possib

相关标签:
1条回答
  • 2021-01-13 21:44

    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");
    
    0 讨论(0)
提交回复
热议问题