translateTimeZone
This function translates a datetime object into its equivalent in a different timezone.
The input object must contain date and time components.
Parameters
DATETIME (datetime or string)
A datetime object, or a string in an automatically recognized datetime pattern.
The input object must have date and time components. It can also include a timezone ID but this is optional. Note you can specify a timezone in the optional third parameter.
OUTPUT TIME ZONE (string)
The timezone to translate to. Give a string representing a regional timezone (e.g. 'America/New_York'). There is a dropdown list of valid timezones in the Function Builder.
INPUT TIME ZONE (string)
Optional. The timezone to translate from. Give a string representing the regional timezone (e.g. 'Europe/Berlin'). There is a dropdown list of valid timezones in the Function Builder.
The function ignores this parameter if the input object contains a timezone ID.
Default: GMT
Examples
When the input object has no timezone AND no timezone is specified in third parameter, the function uses GMT for the starting timezone — that is, the timezone to translate from.
ATL in Script | Result | Notes |
---|---|---|
[[ dateTime = '2019-03-13T10:00:00' translateTimeZone(dateTime,'America/New_York','') ]] | Mar 13, 2019 6:00:00 AM | Converts from GMT (default ) to New York time by subtracting 4 hours. |
[[ dateTime = '2019-03-13T15:00:00' translateTimeZone(dateTime,'Australia/Sydney','') ]] | Mar 14, 2019 2:00:00 AM | Converts from GMT (default) to Sydney time by adding 11 hours. |
These examples show how to use the optional third parameter:
ATL in Script | Result | Notes |
---|---|---|
[[ dateTime = '2019-03-13T15:00:00'; translateTimeZone(dateTime,'Australia/Sydney','Europe/Moscow') ]] | Mar 13, 2019 11:00:00 PM | Converts from Moscow time to Sydney time by adding 8 hours. |
[[ datetime = '2019-03-13T15:00:00Z[Europe/London]'; translateTimeZone(datetime,'Australia/Sydney','Europe/Moscow') ]] | Mar 14, 2019 2:00:00 AM | Converts from London time to Sydney time by adding 11 hours. |
Note
The function ignores the third parameter when the input object has a timezone ID.