- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 12:17 AM
Hi All,
I am not getting time in dubai time zone :_
var gr = "20231130T060000Z";
var formattedDate = gr.substring(0, 4) + '-' + gr.substring(4, 6) + '-' + gr.substring(6, 😎 + ' ' + gr.substring(9, 11) + ':' + gr.substring(11, 13) + ':' + gr.substring(13, 15);
var gdt = new GlideDateTime(formattedDate);
var hours = gdt.getHours();
var minutes = gdt.getMinutes();
var seconds = gdt.getSeconds();
gs.addErrorMessage("Formatted Date: " + hours);
gs.addErrorMessage("GlideDateTime Object: " + minutes);
var formattedTime = hours + ":" + (minutes < 10 ? "0" + minutes : minutes) + ":" + (seconds < 10 ? "0" + seconds : seconds);
var timeOnly = formattedTime;
gs.addErrorMessage("Extracted time: " + timeOnly); // To log the result for verification
This script is not working properly , Can anyone modify the script
Thanks,
Chandan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 12:44 AM
You need to understand the user for GlideDateTime.
When you parse a date / time into GDT then its set as UTC time - ALWAYS.
All date and date time fields in SN is converted into UTC time and depending on your user timezone the display of the fields are local times.
So depending on how you want to store the date time you need to use the same formats.
Example of getting local times out of a GDT:
var time = "20231130T060000Z".replace('T', ' ').replace('Z','');
var gdt = new GlideDateTime();
gdt.setDisplayValue(time, 'yyyyMMdd HHmmss'); //We set the display value if its a local time input - else we use gdt.setValueUTC(<date time input>, <which format it in>)
gs.info(gdt.getValue()); //UTC time
gs.info(gdt.getDisplayValueInternal());//Local time server formated
//Switch between getValue() and getDisplayValueInternal() to change local time with UTC time
var timePartAsArray = gdt.getDisplayValueInternal().split(' ')[1].split(':');
gs.info('Hours ' + timePartAsArray[0]);
gs.info(('Minutes ' + timePartAsArray[1]));
gs.info('Seconds ' + timePartAsArray[2]);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 12:22 AM
what's your business requirement here?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 12:26 AM
I require Only time but in dubai time zone because i want to display or hide the button . Only 8am to 6 pm button should display else hide the button in portal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 12:37 AM
you can use UI action condition and use GlideSchedule
you might already be having a schedule for this. simply use this
How to Hide a Button based on Business/Working Hours of the Assignment Group.
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-03-2024 01:16 AM
Thank you for marking my response as helpful.
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