Next to the datetime fields we are displaying the current logged in user time zone details but its
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
5 hours ago
Hi All,
Good Day.
We have the functionality we need to show the time zone details of the current logged user next to the date & time fields, to achieve this we have implemented one UI Macro as suggested by SNOW HI Team and this macro were added to the attributes list of the date & time fields.
The issue here if we chosen the time zone on the user profile as "Etc/GMT+12" but its showing this like "Etc/GMT-12" next to the date & time fields on the change form.
UI Macro & its script:
Script Include Script:
- Labels:
-
Architect
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
Hi @Susilpa ,
Please refer KB article: https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB1580453#:~:text=Etc/GMT+%2D%2....
- In the ISO 8601 standard, a positive offset means you add time to GMT.
- In the POSIX standard, the convention is the opposite: the sign indicates the direction from GMT, so a positive value represents a time zone west of GMT and a negative value represents a time zone east of GMT.
var TZTimezoneUtils = Class.create(); TZTimezoneUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, { getTimezone: function() { var tzNameMap = { "Asia/Bangkok": "ICST", "Asia/Jakarta": "WIST", "Asia/Manila": "PDT", "Asia/Phnom_Penh": "ICST", "Asia/Saigon": "ICST", "Asia/Taipei": "CDT", "Australia/North": "ACDT", "Australia/South": "ACDT", "BST": "BDST", "Canada/Atlantic": "ADT", "Canada/Central": "CDT", "Canada/Eastern": "EDT", "Canada/Mountain": "MDT", "Canada/Newfoundland": "NDT", "Canada/Pacific": "PDT", "CST": "CDT", "EST": "EDT", "Etc/GMT+12": "GMT+12", // Corrected value "Etc/GMT+11": "GMT+11", "Etc/GMT-3": "GMT-03", // Corrected value "Etc/GMT-7": "GMT-07", // Corrected value "Europe/London": "BST", "GMT": "GMT", "Hongkong": "HKST", "IST": "IDT", "JST": "JDT", "PST": "PDT", "Singapore": "SGST", "US/Arizona": "MDT", "US/Central": "CDT", "US/Eastern": "EDT", "US/Hawaii": "HDT", "US/Mountain": "MDT", "US/Pacific": "PDT" }; var tzName = gs.getSession().getTimeZoneName(); // Handle Etc/GMT format if (tzName.startsWith("Etc/GMT")) { var offsetStr = tzName.substring(7); // Remove 'Etc/GMT' var offset = parseInt(offsetStr); if (!isNaN(offset)) { // Flip the sign and format correctly var sign = (offset > 0) ? '-' : '+'; var hour = Math.abs(offset); return 'GMT' + sign + (hour < 10 ? '0' : '') + hour; } } // Handle Daylight Saving Time lookups if ((new GlideDateTime()).isDST() && tzNameMap[tzName] !== undefined){ return tzNameMap[tzName]; } // Fallback to standard short name return gs.getSession().getTimeZoneShortName(); }, type: 'TZTimezoneUtils'});
If I could help you with your Query then, please hit the Thumb Icon and mark as Correct !!
Thanks, GP
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
What is the need for this complication? The time zone is the one the user selected in its profile. So all you need to do to display the time zone name is to copy field "Time zone" from the current user's profile. As for the offset, that can be obtained by running (new GlideDateTime()).getTZOffset() / 1000 / 60 / 60.
In fact both values are fixed and only change if the user changes the setting on their profile. Given that, I don't even understand why this is needed. Users should know what time zone they have selected for themselves.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 hours ago
what's the business requirement for this?
if you said the code is given by ServiceNow team then does it mean they gave half-working code?
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader