Google Form on Submit get values and format the time

后端 未结 2 994
隐瞒了意图╮
隐瞒了意图╮ 2021-01-27 01:56

I am using Google Apps Script with a Google form. When the user submits the Google Form I get a value from a question. I then take that value and make it a date object, from wha

2条回答
  •  佛祖请我去吃肉
    2021-01-27 02:11

    Try this instead:

    var timeZone = Session.getScriptTimeZone();
    var startT = Utilities.formatDate(start1, timeZone, "h:mm a");
    

    The Utilities.formatDate function expects a time zone that is a valid IANA time zone (such as America/Los_Angeles), not a GMT offset like GMT+0700.

    I am making the assumption that Session.getScriptTimeZone() returns the appropriate zone. If not, then you might need to hard-code a specific zone, or use a different function to determine it.

    Additionally, the +"00" in the script you had was assuming that all time zones use whole-hour offsets. In reality, there are several that have 30-minute or 45-minute offsets.

提交回复
热议问题