Friday 31 May 2024

servicenow glide date time

 https://docs.servicenow.com/bundle/washingtondc-api-reference/page/app-store/dev_portal/API_reference/GlideDateTime/concept/c_GlideDateTimeAPI.html

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0594666

To create a GlideDateTime object with the current date and time, do not provide a parameter. Simply call the constructor of the GlideDateTime class and the value is initialized to the current date and time.

// Do this
var dgt = new GlideDateTime();

Do not use gs.nowDateTime() to set a GlideDateTime object. The nowDateTime() 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.

//Not this
var gdt = new GlideDateTime(gs.nowDateTime());

glide date time is default UTC, you can set timezone :

https://www.servicenow.com/community/in-other-news/demystifying-glidedatetime-and-timezones-also-convert-dates-to/ba-p/2472586

var gdt = new GlideDateTime();
gdt.setTimeZone('US/Eastern');
gs.info(gdt.getDisplayValue());



GlideDateTime - getDisplayValue()

Gets the date and time value in the current user's display format and time zone.

Note: Referring to the GlideDateTime object directly returns the date and time value in the GMT time zone.
Parameters
NameTypeDescription
None
Returns
TypeDescription
ObjectDate and time in the user's format and time zone. Keep in mind when designing business rules or script includes that this method may return values in different formats for different users.

Example

var gdt = new GlideDateTime("2011-08-31 08:00:00");
gs.info(gdt.getDisplayValue());

No comments:

Post a Comment