Someone in the "Europe/London" (UTC +0) Timezone created a Spreadsheet. They input the date "March 22 2019" into one of the fields. This represents the date 3/22/2019 0:00 UTC+O
.
I'm in the "America/Los_Angeles" (UTC -7) Timezone. When I run a Google Apps Script and try to get the value, it's evaluated as:
Thu Mar 21 17:00:00 GMT-07:00 2019
This is accurate since 3/22/2019 0:00 UTC+O
== 3/21/2019 17:00 UTC-7
.
The problem is when I try to get the date programmatically, I'll get it as 21 instead of 22.
For example, if I try to run:
cellRange.getValue().getDate() // returns 21 even though the sheet shows the date as 22
This is because getDate()
returns values "according to local time." The local script time is UTC-7, hence it's returning 21.
However, this causes a dissonance:
- Spreadsheet date: 22 (i.e. the value I see in the sheet)
- Programmatic date: 21 (i.e. the one returned by
getDate()
above)
This is problematic when I'm trying to use a function such as joinDateAndTime_()
with "March 22 2019" as the date and 6am as the time, for example. This causes it to produce a date "March 21 2019 6:00 UTC-7" instead of "March 22 2019 6:00 UTC-7".
What is the best solution here?