Convert Time to different time zones based on the user's selection.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2024 08:12 AM
Hi all,
I'm looking for some assistance in converting time from MST to other 5 different time zones on CR form field.
The 'actual work start' field will auto populate once the CR is moved to implement state and the time it's auto populating is MST irrespective of the selection in 'Time Zone' field. The time it should auto populate and convert into the time zone based on the time zone selected in 'Time Zone' field. I'm able to convert to other time zones accurately but the time in 'actual work start' field it's displaying is UTC time(may be I'm missing something here).
Here is the BR I've written when CR state is 'implement' run 'after' update/insert:
var gdt = new GlideDateTime(); //- utc
gs.print('utc time: '+gdt);
gdt.setTimeZone('US/Arizona');
gs.info('US/Arizona: '+gdt.getDisplayValue());
gdt.setTimeZone('US/Central');
gs.info('US/Central: '+gdt.getDisplayValue());
gdt.setTimeZone('US/Eastern');
gs.info('US/Eastern: '+gdt.getDisplayValue());
gdt.setTimeZone('US/Hawaii');
gs.info('US/Hawaii: '+gdt.getDisplayValue());
gdt.setTimeZone('US/Mountain');
gs.info('US/Mountain: '+gdt.getDisplayValue());
gdt.setTimeZone('US/Pacific');
gs.info('US/Pacific: '+gdt.getDisplayValue());
Output:
But while running the business rule with the same logic and setting it to 'Actual work start', it's displaying the UTC time instead of the converted time zone.
Any help is much appreciated, thanks

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2024 08:48 AM - edited ‎03-27-2024 08:51 AM
Could we see the business rule script?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-27-2024 11:48 PM
Hi Akif
The business rule script is already mentioned above, here it is again:
Here is the BR I've written when CR state is 'implement' run 'after' update/insert:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2024 12:01 AM
Just to make one thing clear, if you got a table having a date column and dates are dynamic from different time zones.
I think you will be able to see those time as per your time zone (system timezone if you have not set your time zone) so, all dates are already converted into system timezone. You just need to use convert it
var time_field = gel('your date field').value;
var selected_timezone = gel('your time zone select field').value;
var time = new GlideDateTime(time_field); // it is the date field, which you want to change according to timezone selected in UI page
var tz = Packages.java.util.TimeZone.getTimeZone(selected_timezone); // here, instead of "America/New_York", you can use the list value of timezone from your UI page.
var timeZoneOffSet = time.getTZOffset();
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);
alert("changed time zone is "+time);
Mark this post as answered if it is correct.
Thanks & Regards,
Pushpanjali
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-28-2024 03:16 AM
Hi @uday_kumar_b,
Can you elaborate on the business need here?
The date/time field will be automatically converted to the timezone of the current user. Hence I don't see a need to convert it with a script.
Cheers