Handling of Java-style (IANA) timezones in script

ILYA STEIN
Tera Guru

My flow needs to create standard changes dynamically and set their start / end datetime to values specified in a custom table. For each datetime value in the table, there is a separate column that specifies its timezone in IANA format, such as 'America/Chicago' or 'US/Eastern'.  When I set the start / end times in the change, they are interpreted as UTC, since the values don't have any time zone suffix attached (e.g., 2026-02-21 23:00:00). I am using GlideDateTime object; invoking its setTimezone method doesn't seem to have any effect. What do I need to do / use to ensure the datetime values are interpreted according to their time zone?

1 ACCEPTED SOLUTION

ILYA STEIN
Tera Guru

Ok, found the solution. At first it seems a little counterintuitive, but it works. So again, my datatime settings look like this:

2025-12-12 23:00:00US/Eastern

I need to set this value correctly in the newly created change request. 

The secret is to set to create a default ('now') datetime object, assign the proper time zone to it, and only after that set your display value. Essentially, substituting the values from the table above, you have the equivalent of the following:

    var startDateTime = new GlideDateTime();
    startDateTime.setTimeZone('US/Eastern');
    startDateTime.setDisplayValue('2025-12-12 23:00:00');
Now, when I look at the change in my time zone (I am in 'US/Central'), the value looks as follows:
2025-12-12 22:00:00 CST
Hope this will help someone who encounters a similar problem!

View solution in original post

1 REPLY 1

ILYA STEIN
Tera Guru

Ok, found the solution. At first it seems a little counterintuitive, but it works. So again, my datatime settings look like this:

2025-12-12 23:00:00US/Eastern

I need to set this value correctly in the newly created change request. 

The secret is to set to create a default ('now') datetime object, assign the proper time zone to it, and only after that set your display value. Essentially, substituting the values from the table above, you have the equivalent of the following:

    var startDateTime = new GlideDateTime();
    startDateTime.setTimeZone('US/Eastern');
    startDateTime.setDisplayValue('2025-12-12 23:00:00');
Now, when I look at the change in my time zone (I am in 'US/Central'), the value looks as follows:
2025-12-12 22:00:00 CST
Hope this will help someone who encounters a similar problem!