Get UTC date and time, day and hours
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 05:27 AM
Hi All,
As part of date and time values to show to user, I need below details in Servicenow:
current utc date and time
current utc day (i.e., monday-sunday)
current utc hour(00 to 23)
Any way to have these 3 values in ServiceNow server side scripting?
Regards,
Venkata
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 05:45 AM
Hello,
Check below thread,
If answer is helpful mark correct!
Thanks,
Pratiksha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-30-2020 06:50 AM
Hi,
you can use getValue() on GlideDateTime() to get value in UTC
sample script below for getting UTC values
var gdt = new GlideDateTime();
var time = new GlideTime();
gs.info('UTC time is: ' + gdt);
gs.info('UTC day of week is: ' + gdt.getDayOfWeekUTC());
gs.info('UTC Hours : ' + time.getHourOfDayUTC());
Output:
day of week - 2 meaning it is Tuesday
Week starts with Monday for UTC
Mark ✅ Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader