1

How to get the user's timezone in the appscript for Gmail add-on. I don't want the script's timezone but user's. I just need to display some history. So if I can convert UTC to user's timezone in client-side, it is also fine.

Session.getScriptTimeZone() gives the script's timezone, not the user's.

Is there a way to get the timezone of the user or show the time according to the user's computer timezone?

Dilip
  • 1,122
  • 11
  • 31

2 Answers2

-1
  1. Session.getScriptTimeZone(); gets the user's timezone that is set on their Gmail account. If the user wants to change their timezone, they have to change it through Google Calendar (how to change timezone).

  2. If you want to get the timezone that reflects the user's computer's settings, here is a small script:

    function getTimeZone(){
        var now = new Date().toString();
        var timeZone = now.replace(/.*[(](.*)[)].*/,'$1');//extracts timezone string
        return timeZone;
    }
  3. Additionally, you can add Moment.js to your Apps Script project and utilize the functions they already built: https://momentjs.com/

SSB
  • 430
  • 4
  • 8
  • I need to show the time according to the user's Gmail timezone or PC timezone. Session.getScriptTimeZone will not give the user's timezone but the script's. Can you refer a document which supports your point? – Dilip Nov 17 '17 at 05:51