Problems with using gs.nowDateTime() or GlideDateTime.getDisplayValue() in a GlideDateTime constructorIssue <!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } To avoid date and time issues in your applications, avoid using gs.nowDateTime() or GlideDateTime.getDisplayValue() in a GlideDateTime constructor. The GlideDateTime constructor has a several options: No-argument: Initializes to the current date/timeGlideDateTime object: Initializes to the same date/time as the argumentString: In the format YYYY-MM-DD HH:MI:SS and is treated as UTC date and time Passing a non-UTC string value leads to time shifts and unexpected behavior in your applications. Release<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Any supported release Cause<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } To create a GlideDateTime object with the current date and time, you should not provide a parameter. Call the constructor of the GlideDateTime class without arguments to initialize the value to the current date and time. // Do thisvar dgt = new GlideDateTime(); //Not thisvar gdt = new GlideDateTime(gs.nowDateTime()); If you use the gs.nowDateTime() method to set a GlideDateTime object, the method returns the date time in local format and the local time zone. The GlideDateTime object uses the date time in the internal format and UTC time zone. The code is uses the display date and time value where it should be UTC instead: var gdt = new GlideDateTime();var gdt2 = new GlideDateTime(gdt.getDisplayValue()); This results in the second GlideDateTime object internal value shifting by an amount equivalent to the time zone offset between the session time zone and UTC. For example: var gdt = new GlideDateTime();gs.info('1. UTC: ' + gdt.getValue());gs.info('2. Local/Dispay: ' + gdt.getDisplayValue()); // Local TZ for this example is America/Los_Angelesgs.info(' ');gs.info('3. nowDateTime: ' + gs.nowDateTime());gs.info(' ');var gdt2 = new GlideDateTime(gs.nowDateTime()); // BAD!gs.info('4. UTC: ' + gdt2);gs.info('5. Local/Display: ' + gdt2.getDisplayValue()); which outputs as: *** Script: 1. UTC: 2022-01-18 16:48:13*** Script: 2. Local/Display: 2022-01-18 08:48:13*** Script: *** Script: 3. nowDateTime: 2022-01-18 08:48:13*** Script: *** Script: 4. UTC: 2022-01-18 08:48:13*** Script: 5. Local/Display: 2022-01-18 00:48:13 In this output, the first GlideDateTime object is initialized to the current date and time since no value was passed to its constructor. Output 2 and 3 display the local date and time formatted according to the glide.sys.date_format and glide.sys.time_format. Output 1 shows the GlideDateTime internal UTC value. The second GlideDateTime object received the local date and time value, which is already offset by UTC -8 because the instance is using America/Los Angeles as its default time zone during the session where the script is run. The GlideDateTime(string) constructor expects a date and time value in UTC, so the American/Los_Angeles date/time value is shifted by -8 hours for both the internal value (4) and display value (5). Using a nonstandard data and time format can lead to more problems. If the GlideDateTime(string) constructor is unable to convert the string to a valid date and time using the yyyy-MM-dd HH:mm:ss format, it tries a number of other "emergency" formats. If the string argument can parse successfully with one of those formats, it may not be what is expected. Enabling Debug Date/Time shows if this is occurring. Common problems can occur when an instance is configured to use a date format like dd/MM/yyyy but is given a date in the format MM/dd/yyyy. For example the 3rd January 2021 as 03/12/2021 using dd/MM/yyyy would match MM/dd/yyyy first and the date would be 12th March 2021. With Debug Date/Time enabled, passing a junk string to GlideDateTime reports all the emergency formats tried in the debug output. As of the Xanadu release, that list, in order, is: yyyy-MM-dd HH:mm:ssyyyy-MM-dd'T'HH:mm:ss.SSSZMM/dd/yyyy HH:mm:ssMM-dd-yyyy HH:mm:ssMM-dd-yyyy HH:mmMM-dd-yyyyMM/dd/yy HH:mm:ssMM/dd/yyyydd-MM-yyyy HH:mm:ssdd-MM-yyyy HH.mm.ssdd-MM-yyyy HH.mmdd-MM-yy HH:mm:ssdd-MM-yy HH.mm.ssdd/MM/yyyydd-MM-yyyyyyyy-MM-dd HH:mmyyyy-MM-dd Note: The gs.nowDateTime() method is not available in scoped applications. Resolution<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } Ensure that display date and time values are not used in a context where UTC is expected. You can make this clearer in code by using the getValue()/setValue() and getDisplayValue()/setDisplayValue() methods consistently throughout the code. Related Links<!-- /*NS Branding Styles*/ --> .ns-kb-css-body-editor-container { p { font-size: 12pt; font-family: Lato; color: #000000; } span { font-size: 12pt; font-family: Lato; color: #000000; } h2 { font-size: 24pt; font-family: Lato; color: black; } h3 { font-size: 18pt; font-family: Lato; color: black; } h4 { font-size: 14pt; font-family: Lato; color: black; } a { font-size: 12pt; font-family: Lato; color: #00718F; } a:hover { font-size: 12pt; color: #024F69; } a:target { font-size: 12pt; color: #032D42; } a:visited { font-size: 12pt; color: #00718f; } ul { font-size: 12pt; font-family: Lato; } li { font-size: 12pt; font-family: Lato; } img { display: ; max-width: ; width: ; height: ; } } GlideDateTime constructor