We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Wrong timezone for GlideDateTime

Michael Nichols
Giga Contributor

I am trying to assign a "latest response date" in a workflow, so I can timeout the whole thing and end it if the customer doesn't respond in time. 

To do this, I am setting:

	var today = new GlideDate();
	var cutoffTime = new GlideTime();
	cutoffTime.setValue('19:00:00');
	workflow.scratchpad.approve_by = new GlideDateTime(today.getDisplayValue() + " " + cutoffTime.getTime());

When I display this to the customer on the Case though, I see: 

Approve by: 2021-04-09 02:00:00

Which is obviously not correct, and I assume is using the wrong timezone. Our instance is set to Sweden/Stockholm (UTC+2), and my user has the same timezone, so why is this producing a time in a different TZ? 

How can I ensure that (a) My display info is correct, and (b) that I _actually_ have the right time (7pm tonight, local time), when I use this value later on in a check?

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

Hi,

getDisplayValue() would always give the time in user's local timezone and not GMT

Can you try this

var today = new GlideDate();

var cutoffTime = new GlideDateTime();
cutoffTime.setDisplayValue(today + ' 19:00:00');

workflow.scratchpad.approve_by = new GlideDateTime(today.getDisplayValue() + " " + cutoffTime.getDisplayValue().toString().split(' ')[1]);

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

11 REPLIES 11

Yes, we have a winner. Thank you - this works nicely 🙂

-O-
Kilo Patron

Can you say what is the time zone for time stamp 19:00:00?