Here is a modified version of the answer, without the UI stuff:
function gasTimezoneOffset(date, hour){
var cal,calTimeZone,calTz,date,dateString,scriptTimeZone,sessionTz;
var testMonth = "March",
testDayOfMnth = "26",
testYr = "2016",
hour = "10:00",
timeZoneDiff = 0;
Logger.log("Script Time Zone: " + Session.getScriptTimeZone());
dateString = testMonth + " " + testDayOfMnth + ", " + testYr;
Logger.log("dateString: " + dateString);
date = new Date(dateString);
cal = CalendarApp.getDefaultCalendar();
calTimeZone = cal.getTimeZone();
calTimeZone = Utilities.formatDate(date, calTimeZone, 'Z');
scriptTimeZone = Utilities.formatDate(date, Session.getTimeZone(), 'Z');
calTz = Number(calTimeZone.slice(0,3));
sessionTz = Number(scriptTimeZone.slice(0,3));
//If both time zones are the same sign, get the difference between the
//two. E.g. -4 and -2. Difference is 2
//if each time zone is a different sign, add the absolute values together.
//-4 and +1 should be 5
if (calTz < 0 && sessionTz > 0 || calTz > 0 && sessionTz < 0){
timeZoneDiff = Math.abs(Math.abs(calTz) + Math.abs(sessionTz));
} else {
timeZoneDiff = Math.abs(Math.abs(calTz) - Math.abs(sessionTz));
};
hour = Number(hour.slice(0,2));
return hour + timeZoneDiff;
};
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…