Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

CovertTimeZone not converting zones correctly

MarkoS2
Tera Expert

I am using the script to convert the source timezone (Pacific Time) to local timezone (Europe/Belgrade)

The script works fine, it does calculate, but result is not correct.

 

 

var targetTimeZone = 'Europe/Belgrade';

var sourceTimeZone = 'US/Pacific';

var startDateTime = new GlideScheduleDateTime('25-03-2024 05:00:00');
var endDateTime = new GlideScheduleDateTime('25-03-2024 14:00:00');
startDateTime.convertTimeZone(sourceTimeZone, targetTimeZone);	
endDateTime.convertTimeZone(sourceTimeZone, targetTimeZone);
gs.print(startDateTime);
gs.print(endDateTime);

 

 

This returns 8 hour differential: 

*** Script: 2024-03-25 13:00:00
*** Script: 2024-03-25 22:00:00

Which does not seem to be correct since Pacific is currently using PDT (9 hour difference of Belgrade)

Why does this happen and how to fix it?

Thanks!

0 REPLIES 0