Convert date time to another timezone

John Doe
Giga Expert

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);

 

@Ankur Bawiskar 

1 ACCEPTED SOLUTION

Kieran Anson
Kilo Patron

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());

find_real_file.png

View solution in original post

9 REPLIES 9

Kieran Anson
Kilo Patron

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());

find_real_file.png

Error facing


Evaluator.evaluateString() problem: com.glide.script.fencing.MethodNotAllowedException: Function print is not allowed in scope sn_vul_qualys. Use gs.debug() or gs.info() instead: com.glide.script.fencing.ScopedScriptableObject.checkWhitelistAccess(ScopedScriptableObject.java:137)

Hi,

please use gs.info() in scoped app instead of gs.print()

Regard
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Now its not throwing error but not printing anything