Script inserted today's date into spreadsheet is wrong

我只是一个虾纸丫 提交于 2020-07-10 09:56:26

问题


I'm working on a bounded to spreadsheet script for a client, the spreadsheet is owned by them. Among other many things the script should insert today's date into a Google Sheets spreadsheet cell. The problem is that the inserted date is wrong and always the same.

I made a copy of the spreadsheet to try to debug my code / find out what setting is wrong but I'm unable to reproduce the problem, like looking at and playing with the spreadsheet and script project timezone settings.

This is the "minimum" code to insert today's date

function customToday(){
  var now = new Date();
  var spreadsheet = SpreadsheetApp.getActiveSpreadsheet();
  var sheet = spreadsheet.getSheets()[0];
  var range = sheet.getRange('A1');
  range.setValue(now.getFullYear(),now.getMonth(),now.getDay())

}

Replacing now.getDay() by other value doesn't change the result.


回答1:


I finally look to the original spreadsheet settings. The regional setting was blank and the timezone setting was Pacific Time rather the default timezone of the spreadsheet owner.

It looks to me that somehow the regional and timezone settings were corrupted. Changing the regional settings to the client default country and timezone fixed the problem.



来源:https://stackoverflow.com/questions/54985339/script-inserted-todays-date-into-spreadsheet-is-wrong

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!