How to get current date time in user logged in time zone - client scripts
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2022 10:51 PM
Hello,
I am using var nowTime = new Date().getTime(); to get the current date time, but this is not returning in logged is user timezone.
Can anyone please let me know how to get urrent date time in user logged in time zone in client scripts
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2022 10:57 PM
Hi,
you cannot get that in client side; please use GlideAjax and use script include
this line will work in server side
var timeZone = gs.getUser().getRecord().getValue('time_zone');
gs.info(timeZone);
Output:
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2022 11:13 PM
I need to get the current date time in user specified timezone which was selected in user profile.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2022 11:22 PM
Hi
var nowTimeis=new GlideDateTime().toString();
var timeis=nowTimeis.split(' ')[1];
gs.print(timeis);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-26-2022 11:26 PM
Hi,
this would give you in server side
var gdt = new GlideDateTime();
gs.info(gdt.getDisplayValue());
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader