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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-04-2019 11:14 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-06-2019 02:22 AM
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 :-
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