Getting current user timezone

google-apps-script

Solution

Greg, normal javascript seems to be working as intended this might be new in gas. The second example of code's function is returning the correct timezone offset for me. I'm currently using the Session.getTimeZone() in a gasOffsetScript. Question here might be a good read for the future. Using Calendar Timezone to set event Timezone, not the users

This next code will get the users timezone based off their default Calendar Setting, if the script is running as the user.

function getUserTimeZone() {
  var userTimeZone = CalendarApp.getDefaultCalendar().getTimeZone();
  Logger.log(userTimeZone)
}

Or you could modify the following using normal javascript.

Code that is returning users timezone Stackoverflow question

function userTimeZone() {
  function pad(number, length){
    var str = "" + number
    while (str.length < length) {
        str = '0'+str
    }
    return str
}

var offset = new Date().getTimezoneOffset()
offset = ((offset<0? '+':'-')+ // Note the reversed sign!
          pad(parseInt(Math.abs(offset/60)), 2)+
          pad(Math.abs(offset%60), 2))
  Logger.log(offset)
}

Good luck brother, timezones are thorns.

Problem

I have been using `Session.getTimeZone()` to get the current user's timezone. I just noticed it has been deprecated, and I can't see anything that replicates this functionality. My users are located all over the US and dates/times should be formatted accordingly. How can I get the current user's timezone and not that of the script/owner? The project in question is a standalone script.

Original source

Related problems