I am new to Google App Script (and Javascript) and am having troubles with constructing dates to put into a Google Calendar event. Moreover the handling of British Summer Time is causing a problem.
In the UK dates are written in the format dd/MM/yyyy. So the spreadsheet from which I read the date has them in this format.
07/01/2021 (which means 7th January 2021, not 1st July 2021)
So reading this into Google App Script using
var data = sheet.getDataRange().getValues()
// The first part of the code gets the date from the spreadsheet and converts to MM/dd/yyyy format
timeofevent = data[0][0]
var newtime = Utilities.formatDate(new Date(timeofevent), calendar.getTimeZone(), "MM/dd/yyyy")
var newstart = newtime + " 15:00:00 GMT" // my event always runs from 3pm til 4pm on given date
var newend = newtime + " 16:00:00 GMT"
// Then I create a date object of these times and pass to create event with options
var nstart = new Date(newstart)
var nend = new Date(newend)
calendar.createEvent("Test",nstart, nend, options)
Provided the UK is on GMT (half of the year) this works fine when putting in an event. However when in British Summer Time, the event is out by an hour when created. How do I input a timezone or create a date which is handled correctly for GMT or BST. And is there a better way of doing what I have done so far?
Many thanks.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…