Calculating time difference between a catalog variable date and current system date

Joe Trimble
Tera Expert

I am developing a Flow Designer flow with a "Wait for Condition" action that has a timeout.   The timeout value should be the relative time between a catalog variable "due_date" and the current date/time.  I am in the US/Central timezone (UTC-5 currently).  When my script retrieves the "due_date" it come back in UTC time, but when I retrieve the current date/time it retrieves the time in my current timezone.  The result is that my relative time interval in the "Wait for condition" timeout value is off by 5 hours.

 

How can I compare a variable in UTC time with my current time in US/Central?  I can't figure out how to get both values in the same timezone value to compare them properly.

 

Thanks for any guidance!

Joe

1 ACCEPTED SOLUTION

Vrushali  Kolte
Mega Sage

Hi @Joe Trimble ,

You can use below script to convert the UTC time into US/Central time.

 

var time = new GlideDateTime();

gs.info('UCT Time ' + time);

var targetTimezone = 'CST'; // ensure you give correct timezone Abbreviation

var tz = Packages.java.util.TimeZone.getTimeZone(targetTimezone); 

time.setTZ(tz);

var timeZoneOffSet = time.getTZOffset();

time.setNumericValue(time.getNumericValue() + timeZoneOffSet);

gs.info('CST' + time);

 For more information you can refer below below community blog.

https://www.servicenow.com/community/developer-blog/convert-timezone/ba-p/2287262.

 

If my answer solved your concern please mark it as Helpful 👍 and Accepted ✔️.

View solution in original post

2 REPLIES 2

Vrushali  Kolte
Mega Sage

Hi @Joe Trimble ,

You can use below script to convert the UTC time into US/Central time.

 

var time = new GlideDateTime();

gs.info('UCT Time ' + time);

var targetTimezone = 'CST'; // ensure you give correct timezone Abbreviation

var tz = Packages.java.util.TimeZone.getTimeZone(targetTimezone); 

time.setTZ(tz);

var timeZoneOffSet = time.getTZOffset();

time.setNumericValue(time.getNumericValue() + timeZoneOffSet);

gs.info('CST' + time);

 For more information you can refer below below community blog.

https://www.servicenow.com/community/developer-blog/convert-timezone/ba-p/2287262.

 

If my answer solved your concern please mark it as Helpful 👍 and Accepted ✔️.

Joe Trimble
Tera Expert

Thanks, Vrushali.  This is very helpful.