variable returning GMT while gs.nowDateTime() returns local timezone

conanlloyd
Giga Guru

I have a requirement to update a notification generator to have a scheduled time to send.  On the surface it looked easy as I just needed a timer in the workflow after the approval to wait until the requested date/time.  Here is my timer script, (forgive the log statements):

//Set variables
var userTime = current.variables.when_to_send;
var nowdt = new GlideDateTime(gs.nowDateTime());
gs.log("CDL: nowdt " + nowdt);
gs.log("CDL: userTime " + userTime);

//Calculate time difference between nowdt and userTime in seconds
answer = gs.dateDiff(nowdt,userTime, true); 
gs.log("CDL: answer " + answer);

The problem is that when I run it, userTime is returning a time in GMT while nowdt is returning a time in my local EST! So instead of returning a value of approximately 400 seconds between the nowdt of 14:58:17 and the 15:05 of the userTime, it gave me what is below.

find_real_file.png

Anyone able to help me figure out how to get both into the same timezone?

 

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

This revised script will show you the correct number of seconds in your answer log - just take out the gs.nowDateTime()

//Set variables
var userTime = current.variables.when_to_send;
var nowdt = new GlideDateTime();
//gs.log("CDL: nowdt " + nowdt);
//gs.log("CDL: userTime " + userTime);

//Calculate time difference between nowdt and userTime in seconds
answer = gs.dateDiff(nowdt,userTime, true); 
gs.log("CDL: answer " + answer);

View solution in original post

5 REPLIES 5

Thanks Brad!!  crazy to think it was that simple but I got the right number of seconds back now.  Just have to wait until 4:45 to see if the notification fires off.