setTimeZone
Sets the timezone ID or offset for a datetime object.
If the input object already has a timezone ID or offset, the function overwrites it.
Any date and time components in the input object are unchanged.
Parameters
DATETIME (datetime or string)
A datetime object, or a string in an automatically recognized datetime pattern.
If the input is date-only (e.g. '2019-02-07') or time-only (e.g. '22:30'), the function returns a warning.
TIME ZONE (string)
A string representing a regional timezone (e.g. 'Europe/Berlin'). There is a handy dropdown list of valid timezones in the Function Builder. Alternatively, you can give a fixed offset (e.g. '+02:00').
Examples
ATL in Script | Printed Result |
---|---|
[[ dateTimeObject = parseDateTime('2017-12-25T11:30:00Z[Europe/London]') setTimeZone(dateTimeObject, 'Australia/Sydney') ]] | Dec 25, 2017 11:30:00 AM |
The first line creates a datetime object with the timezone 'Europe/London'. The second line changes the timezone to 'Australia/Sydney'. This change isn't visible here because the default formatting does not show timezones or offsets. To see the change, use formatDateTime.
ATL in Script | Printed Result |
---|---|
[[ dateTimeObject = parseDateTime('2017-12-25T11:30:00Z[Europe/London]') newDateTimeObj = setTimeZone(dateTimeObject, 'Australia/Sydney') formatDateTime(newDateTimeObj, 'MMM dd, yyyy hh:mm:ss a VV') ]] | Dec 25, 2017 11:30:00 AM Australia/Sydney |
This similar example shows how to set an offset:
ATL in Script | Printed Result |
---|---|
[[ dateTimeObject = parseDateTime('2019-02-20T00:30') newDateTimeObj = setTimeZone(dateTimeObject, '-04:00') formatDateTime(newDateTimeObj, 'MMM dd, yyyy hh:mm:ss a xx') ]] | Feb 20, 2019 12:30:00 AM -0400 |