ServiceNow has the incorrect local time for me (Time Zone US/Eastern)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2022 04:06 AM
When I instantiate a new GlideDateTime object :
var gdt = new GlideDateTime("15-04-2022 16:30:00");
gs.info(gdt.getDisplayValue());
It gives the output:
2022-04-15 12:30:00 PM
It stores a time of day that is four hours ahead of my local time. I am in the US/Eastern Time Zone.
Where is this incorrcect time pulling from? How can I alter this?
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-15-2022 05:50 AM
Hi Akshita,
You are instantiating the GlideDateTime object correctly.
It is best that you do not use getDisplayValue() on a gdt object. In that case it passes in a string and if it is not UTC then it will mess up the time as you have seen.
If you would have simply printed the variable it should be correct:
var gdt = new GlideDateTime("15-04-2022 16:30:00");
gs.info(gdt);
*** Script: 2022-04-15 16:30:00
You can also refer to this article from ServiceNow where they explain why you should not use getDisplayValue on a gdt object.
Hope this helps.
Kind regards,
Fernando