Odd Issue of Date Changing in Script Output

前端 未结 3 1685
孤街浪徒
孤街浪徒 2020-12-20 09:25

A colleague of mine has written a Google Apps script to automate a workflow (approving room comp requests at a hotel). The script, by and large, seems to be functioning as

3条回答
  •  温柔的废话
    2020-12-20 09:45

    I had a similar problem but mine was from entering the date in a form in the format MM/dd/yyy. When getting the date from the spreadsheet to post to an email, it was always one day less.

    I'm in Eastern time (GMT-5:00). I verified that it was correct in my Project properties and my Spreadsheet setting. After digging deeper, I realized that although the date entered in the form and displayed in the spreadsheet was 7/27/2012 the actual date in the spreadsheet was:

    Thu Jul 26 21:00:00 PDT 2012

    This made "some" sense, as 7/27/2012 00:00:00 Eastern Time (GMT-5:00) would be the day before in PDT by three hours. I simply formatted the date GMT. I could have formatted it to EDT, and it should have always worked, but hard coding it GMT more or less took the guessing out of someone else reading the code if the code would need to be changed as the seasons changed. I only needed the date.

    I did copy and paste the FUS1 example in this post (for now as comments) as a more "eloquent" way of handling the problem. Thanks!

提交回复
热议问题