
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2019 04:47 AM
Hi All,
How do I get timezone offset and day light saving applicable?(true or false) for opened for user timezone.
We have requiremnt in which we need to populate this values in notification.
currently I could only get user time zone by doing dot walking in opened for field.
Any input on this would be much appreciated 🙂
Solved! Go to Solution.
- Labels:
-
Best Practices
-
Incident Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2019 06:50 AM
Try that:
var openedFor = gs.getUser().getUserByID('opened_for');
var tz = Packages.java.util.TimeZone.getTimeZone(openedFor.getTZ()); //set time zone based on user record
var time = new GlideDateTime(); //utc
time.setTZ(tz); //set time based on tz variable
var timeZoneOffSet = time.getTZOffset(); // calculate offset from utc
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);
gs.print('the time you're looking for: ' + time)
Regarding Daylight Saving Time it depends what value is set on sys_user table:
"In general, if a time zone is specified based on location (for example, America/Los Angeles), the system automatically adjusts for daylight saving time. If a time zone is specified based on the name of a time zone (for example, GMT), which is discouraged, it does not typically adjust for daylight saving time."
https://docs.servicenow.com/bundle/istanbul-platform-administration/page/administer/time/reference/r_TimeZones.html
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2019 05:22 AM
You probably need to use getLocalTime():
var gdt = new GlideDateTime();
gdt.getLocalTime();

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2019 05:25 AM
Thanks for the reply 🙂
but it is for the logged user right i,e me here..
but how do i pass opened for(caller of an incident) timezone and get it confirmed that the daylight saving is applicable?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2019 06:50 AM
Try that:
var openedFor = gs.getUser().getUserByID('opened_for');
var tz = Packages.java.util.TimeZone.getTimeZone(openedFor.getTZ()); //set time zone based on user record
var time = new GlideDateTime(); //utc
time.setTZ(tz); //set time based on tz variable
var timeZoneOffSet = time.getTZOffset(); // calculate offset from utc
time.setNumericValue(time.getNumericValue() + timeZoneOffSet);
gs.print('the time you're looking for: ' + time)
Regarding Daylight Saving Time it depends what value is set on sys_user table:
"In general, if a time zone is specified based on location (for example, America/Los Angeles), the system automatically adjusts for daylight saving time. If a time zone is specified based on the name of a time zone (for example, GMT), which is discouraged, it does not typically adjust for daylight saving time."
https://docs.servicenow.com/bundle/istanbul-platform-administration/page/administer/time/reference/r_TimeZones.html

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-19-2019 09:33 PM
Thank you so much for your reply:)
As we all know that the time zone conversions are managed by the platform automatically in servicenow,
I have created a mail script as suggested,
for Offset,
var gdt = new GlideDateTime();
template.print(gdt.getTZOffset()/3600000);//to convert it form milliseconds
for dst,
var gdt = new GlideDateTime();
template.print(gdt.isDST());