How can I display date field with considering timezone?

Tomoaki Tagawa1
Tera Contributor

Hi all,

I would like to display date field for every global user.

 

For example, if Japanese users see a data field A as 2019-02-11 in the Japanese morning,

At the same time I would like US users to see a date field A as 2019-02-10 in the US evening.

I know date/Time field is automatically calculate time in the database and display according to their local timezone. ( For example, update and created field.)

 

Best regards,

Tomoaki

1 ACCEPTED SOLUTION

Mrigank Gupta
Giga Expert

var datetime = new GlideDateTime();

datetime.getDisplayValue() ---> This will give you what you need. The same date but in the current user's timezone.

You can use this link for more info.

https://www.linkedin.com/pulse/working-dates-servicenow-mrigank-gupta/

View solution in original post

8 REPLIES 8

Mrigank Gupta
Giga Expert

You are correct. Service platform will show the date field after converting it to current user's timezone.

This should resolve your issue. Or do you want to show the same date field in different time zone in same form at same time?

Hi Mrigank,

Thank you for your replying, but as you thought, I was not able to resolve my issue.

I fill my date type field with script below, but not converted to each user's timezone.

Where is bad point?

 

(function executeRule(current, previous /*null when async*/) {

var datetime = new GlideDateTime();
current.u_answer_date = datetime.getDate();

})(current, previous);

var datetime = new GlideDateTime();
current.u_answer_date = datetime.getDate();

This will only get the UTC timezone because of the functionality of SN

var datetime = new GlideDateTime().getLocalDate();
current.u_answer_date = datetime;

For your requirement this fits your requirement.

Mrigank Gupta
Giga Expert

var datetime = new GlideDateTime();

datetime.getDisplayValue() ---> This will give you what you need. The same date but in the current user's timezone.

You can use this link for more info.

https://www.linkedin.com/pulse/working-dates-servicenow-mrigank-gupta/