- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2022 09:01 PM
To be specific, I'm working in scoped application Qualys one, there I need to convert timezone, it seems it is not working there using Javapackages, can anyone help? Also I am trying to debug using fix script but it is not printing any output
I tried this thing also
var time = new GlideDateTime(); // Display date retrieved
gs.print('GMT Time: '+time); // Set timezone
var tz = Packages.java.util.TimeZone.getTimeZone("America/New_York");
//var tz = Packages.java.util.TimeZone.getTimeZone("IST");
time.setTZ(tz); // Get offset of timezone set above
var timeZoneOffSet = time.getTZOffset(); // Add offset to current time
time.setNumericValue(time.getNumericValue() + timeZoneOffSet); // Print date/time in desired timezone
gs.print('Eastern time: '+time);
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2022 09:30 PM
Hey,
Package calls aren't allowed in scoped applications. If you want to change the Timezone of a GlideDateTime object you can use the following.
var now = new GlideDateTime();
gs.print("System Time is " + now);
var gsdt = new GlideScheduleDateTime(now);
gsdt.setTimeZone("Europe/London");
gs.print("London time is " + gsdt.getGlideDateTime().getDisplayValue());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-04-2022 09:32 PM
Hi,
check script shared by Kieran
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
09-04-2022 09:55 PM
this works well in scoped app as well
var dateTime = new GlideDateTime();
var sourceTimeZone = 'GMT';
var targetTimeZone = 'IST';
var finalValue = global.rmConvertTimeZone(dateTime, sourceTimeZone, targetTimeZone);
gs.info(finalValue);
[0:00:00.063] Script completed in scope x_421457_testing: script
Script execution history and recovery available here
x_421457_testing: 2022-09-05 10:25:27
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
09-04-2022 10:57 PM
Did you check script I shared? It works well
Somehow I ran the script shared by Kieran and it seems it's not showing the correct output
I used Europe/Berlin and Berlin is 2hours ahead of GMT but it shows only 1 hour ahead
var now = new GlideDateTime();
gs.info("System Time is " + now);
var gsdt = new GlideScheduleDateTime(now);
gsdt.setTimeZone("Europe/Berlin");
gs.info("Berlin time is " + gsdt.getGlideDateTime().getDisplayValue());
[0:00:00.106] Script completed in scope x_421457_testing: script
Script execution history and recovery available here
x_421457_testing: System Time is 2022-09-05 05:56:34
x_421457_testing: Berlin time is 2022-09-05 04:56:34
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
09-04-2022 11:47 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-20-2023 06:53 AM
how to convert date and time of selected timezone to UTC irrespective of user's time zone and system's time zone.
Note: I am using Script include with two inputs from client script
input1 : date and time selected by user( any future date as well).
input2 : Time zone
Expected output from my script to get Date and time in UTC
Regards
Shiva Reddy