Getting Current Time for different Timezones
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2023 04:08 AM
Hi,
How Can I get the Current time for different timezones in script include.
For eg Current time in EST/PST/US Mountain etc. User can have any timezone setting in Profile like EST or PST but script should always give current time based on Timezone name passed.
I am working in scoped app and using below api
GlideScheduleDateTime(gdt).convertTimeZone(Timezone1 , TimeZone2);
But this is giving correct result only if user has Timezone setting in profile as GMT , It is failing is user has timezone setting as EST or PST in profile.
Thanks
Deepak

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2023 05:23 AM
Hi,
If you are working in Global scope, then you have the option of using
gs.nowDateTime();
which returns the time in the current users time-zone setting.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2023 06:06 AM
Hi @deepak50 ,
Certainly! If you want to generate the current date in UTC using GlideDateTime in ServiceNow, you can follow this code snippet:
gs.info(new GlideDateTime());
The following code will return the current date/time in the specific timezone you want:
vargt =newGlideDateTime();
gt.setTimeZone('PST');//["US/Eastern" , "US/Eastern" , "PST" ]
gs.info(gt.getDisplayValue());
You can utilize the above code in server-side scripting.
If this helped you in any way, please hit the like button/mark it helpful. So it will help others to get the correct solution.
regards,
Prasad
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-24-2023 01:50 AM
Hi Prasad, I am working in app scope , so setTimeZone is giving error:
problem: java.lang.SecurityException: Function setTimeZone is not allowed in scope
Thanks
Deepak

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-27-2023 05:15 AM
@deepak50 , Didn't found any solution yet. But could you please try making your application cross-scoped by providing cross-scope privileges?
-Prasad