
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 05:25 AM - edited 08-31-2023 05:28 AM
Hello. Does someone have a function to parse the ZoneInfo array (?) or whatever it is that is returned from:
var userTimeZone = gs.getSession().getTimeZone();
The output from that looks like this:
sun.util.calendar.ZoneInfo[id="US/Eastern",offset=-18000000,dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=US/Eastern,offset=-18000000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,endTimeMode=0]]
I care about the id, "US/Eastern" in this example...
and the "offset", -18000000 in this example.
*** OR ***
Is there a better way to get the name/id and the offset?
I know that I can get the name with a different function:
var userTimeZoneName = session.getTimeZoneName();
But I don't know the best way to get the offset. Thanks.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 06:10 AM
Hi,
Using string manipulation we can get the offset. But might not be a best way.
var userTimeZone = gs.getSession().getTimeZone()+'';
gs.print(userTimeZone);
userTimeZone = userTimeZone.replace('sun.util.calendar.ZoneInfo','');
gs.print(userTimeZone);
var tmArr = [];
tmArr = userTimeZone.split(",");
gs.print(tmArr[1]);
var offset = tmArr[1]+'';
offset = offset.replace('offset=','');
gs.print(offset);
Regards,
Karthik Nagaramu
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 06:09 AM
what's your business requirement?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 09:14 AM
The business requirement was to get the Offset, to know how far ahead or behind the user is in Time.
Why do you ask though? Is this object not something that should typically be used?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 06:10 AM
Hi,
Using string manipulation we can get the offset. But might not be a best way.
var userTimeZone = gs.getSession().getTimeZone()+'';
gs.print(userTimeZone);
userTimeZone = userTimeZone.replace('sun.util.calendar.ZoneInfo','');
gs.print(userTimeZone);
var tmArr = [];
tmArr = userTimeZone.split(",");
gs.print(tmArr[1]);
var offset = tmArr[1]+'';
offset = offset.replace('offset=','');
gs.print(offset);
Regards,
Karthik Nagaramu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2023 12:47 PM
Final poor man's version:
//Note: This TimeZone object may then be used directly in the GlideDateTime setTZ() function. There may be no need to parse it.
//Get TimeeZone object from session.
var userTimeZone = gs.getSession().getTimeZone() + '';
//Strip off weird string before the start of the array.
userTimeZone = userTimeZone.replace("sun.util.calendar.ZoneInfo[", "");
//Strip off trailing two right brackets.
userTimeZone = userTimeZone.substr(0, userTimeZone.length - 2);
//Split the remaining string into array elements, using , as the delimiter.
var tmArr = [];
tmArr = userTimeZone.split(",");
//Get the id, the first element, and strip off double quotes.
var id = tmArr[0] + "";
id = id.replaceAll('"', "");
//Get the offset, the second element, and strip off the term "offset=".
var offset = tmArr[1] + '';
offset = offset.replace('offset=' , '');