Time zone conversion in Google Sheets

Time zone conversion in Google Sheets

Google Sheets does not have a built in way of converting time zone data but by using the power of Moment.js and Google’s script editor we can add time zone functionality to any sheet.

First, we need to add the Moment.js code as a library that can be shared between different documents. This is the javascript library that adds date and time zone manipulation support. A good way to do this is to create it from Google Drive so it can be easily edited and shared with all your sheets.

In Google Drive, go to New > More > Connect more apps and choose Google Apps Script. Now, create a new Google Apps Script document. This will open the Google script editor. Call the project ‘Moment’ and create two files in the project called moment.js and moment-timezone.js using the moment and moment-timezone libraries. Make sure you choose one of the moment-timezone files with time zone data. You should end up with a project something like this:

To easily use this in multiple sheets we can publish it as a library. Go to File > Manage versions and save a new version. We are nearly finished here but before we move on go to File > Project properties and make a note of the project key, you will need this to refer to your library in your sheets.

In our test we are going to use our new library to convert times in a local time zone to UTC.

Create a new Google sheet and enter a date in A1 and a time zone in B1, like this:


Go to Tools > Script editor and create a project called Functions. In the script editor, go to Resources > Libraries and using the project key you made a note of before add your Moment library and select version 1. I prefer to use a shorter identifier like ‘m’. Click save and your library is now accessible to your sheet’s script. We can create a function to convert to UTC like this:

Save your project and you can now use this function in your sheets like this:


16 thoughts on “Time zone conversion in Google Sheets”

  • Thank you for this information! It was a life saver. I was using moment.js in my google sheets project but I was working with a client based in India. The spreadsheet settings were set for the right timezone but moment would still bring up the wrong timezone. So I searched and found your post here and it worked out great! Thanks again.

  • Hi David

    Thank you sooo much!! You have no idea of the countless hours I’ve been looking for this!!


  • Hello David,

    First of all, thank you very much for this script, it’s going to be very useful for me. However, I have an error with my sheet, it tells me “TypeError: Cannot read property “version” from undefined. (line 27).” which corresponds to this part of the script: “var VERSION = “0.5.13”,”
    Is there something I’m missing?

    Thank you so much for your help,


  • It sounds like the problem is this bit:

    Do you have both moment.js and moment-timezone.js (moment-timezone-with-data-2012-2022.js) in your script project (check out the screenshot in the post)?


  • Hi David – I’m having the same issue as the above commenter. Just confirmed that I’m using the right scripts.

  • I think I can reproduce this. It looks like the order of scripts in the script editor is important.

    Make sure you have the moment.js script above the moment-timezone.js script:

    If yours is the other way round just remove and re-add moment-timezone.js and it will place it underneath. Publish a new version of your library and update the version used in your sheet.

  • Doesn’t seem to be the root of the issue for me. Moment.js is at the top: https://screencast.com/t/1L4p1Kgoi

    This thread points out that you need to have data accompanying the scripts…but I’m using moment-timezone (with data) version.

    Thread: https://github.com/moment/moment-timezone/issues/465

  • Hi David. Thank you for the post. The code works. However if I want the conversion to be to EET Time, let’s say UTC+02:00, what do I need to change in the function?

  • If you want to customise the target time zone you can add this function to your script:

    Then call it from your sheet by passing in the source and target time zones like this:

    I have updated the example sheet with this new function.

    This list of time zones in the tz database is very useful.

  • How can I simply retrieve the browser timezone directly using something like:


    This way, if you are a ‘gamer’ and you have guild members located in various locations around the world but you want a Google Sheet to display ‘their’ local time when planning events, we don’t have to create mass amounts of rows simply so people can copy/paste their own location in order to get their local time for scheduled events.

  • Yep you can do that!

    I’ve added the function to the example sheet.

  • David, how do I do this timezone conversion programmatically? (without the use of the spreadsheet)

  • Derek, Google Scripts are Javascript so as long as you have Moment.js loaded you can use the same function in your regular Javascript projects.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.