Friday, March 11, 2011

Demystifying Time Zones in Apps Script - Part 1

Dealing across time zones is complicated not only in real life but also in software programming. In Apps Script, we have support multiple time zones while keeping it simple. When you are writing scripts, you may have to manage time zone conversions because each service you use may operate in its own time zone.

In Apps Script, there are a few basic concepts when it comes to time zones.

  1. A script has its own independent time zone property. It does not share the time zone with either a user’s browser or a spreadsheet. A script’s time zone can be modified using the File > Properties menu in the Script Editor.

  2. A script executes in its own time zone context. Each script is guaranteed an execution environment that uses the script’s predefined time zone. For example, different scripts executing var date = new Date(); may get different dates depending on the time zone of the respective script.
Stay tuned for part 2!

Saurabh Gupta, Google Developer Relations