What is the function of GlideDateTime API setTZ(TimeZone timeZone)

Rakesh Goel
Kilo Expert

ServiceNow GlideDateTime provides a function called gdt.setTZ(TimeZone timeZone) to change the timezone of GlideDateTime object. The question is that GlideDateTime stores date/time using UTC Standard date/time world clock which is a standard time and it is neutral to timezone. So what is the meaning of setting the TimeZone of the GlideDateTime object?

 

 

1 REPLY 1

Amit Gujarathi
Giga Sage
Giga Sage

Hi Rakesh ,

The setTZ method is Sets the time zone of the GlideDateTime object to be the specified time zone.

 

GlideDate time provides different methods for both i.e. for UTC and local time as we can see in the below image :-

find_real_file.png

 

The setTZ method will be applicable when you are using local time methods , to change the reference timezone .

 

Script example :-

var tz = gs.getSession().getTimeZone();
var gdt = new GlideDateTime(); 
gdt.setTZ(tz);

 

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.

Regards,

Amit Gujarathi

 


Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi