- 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: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]);