GlideDateTime Question

zynsn
Tera Expert

Hi Developers,

 

I am curious as to why one method works and the other one doesn't. I have a script that is being triggered from a UI action to populate date/time field when it is triggered.

 

This script is giving me the GMT time on the field which is not what I'm looking for.

 

var currentTime = new GlideDateTime();

current.variables.abc = currentTime.getDisplayValue();

 

 

This line below is giving me the result I want, which is seeing the field in my timezone.

 

current.variables.abc = new GlideDateTime();

 

 

I am not sure why both are producing different results. Please help me clarify.

 

2 REPLIES 2

Manmohan K
Tera Sage

Hi @zynsn 

 

The below is how ServiceNow built the GlideDateTime Class

 

gs.print(new GlideDateTime());   //Gives Time in UTC

Outpot -  2023-06-02 18:40:44   

 

 

 

 

gs.print(new GlideDateTime().getDisplayValue());  //gives time in User's profile time zone which in this case is US/Central

Output -  2023-06-02 13:40:44

 

 

User's selected Time zone

ManmohanK_0-1685731538175.png

 

Ranjit Nimbalka
Mega Sage

Hi @zynsn 

Take a look on this document this describes very well.

https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0594666#:~:text=The%20nowDate....

 

Regards,

Ranjit Nimbalkar