How to set different timezone with login user

SystemsGo
Tera Contributor

Hi experts,

I need help from you about timezone.

 

I want to set time in Work order/ Work order task form.

My timezone (user's timezone) is different with Customer (Account) timezone. I want the time displayed as the customer's timezone.

For example,

my timezone is Asia/Tokyo, the customer's Timezone is Asia/Hong Kong.

I want Set the start Time to 9:00 AM which based on customer's timezone. When I put in the time 9:00 AM in work order/Work order task form, then submit the form.

The time will displayed as 10:00AM for me(time Zone Asia/Tokyou).

How can I implement this?

So far my code is like below, but it just set the time to the timezone of my ServiceNow("Asia/Tokyou"). can you please guide me how to change the timezone?

Thank you.

var startDateTime = new GlideDateTime();
var strsDate = "2022-12-29 9:00:00";
startDateTime.setDisplayValue(strsDate);
startDateTime.setTZ(tz);
var starttimeZoneOffSet = startDateTime.getTZOffset();
starttimeZoneOffSet.setNumericValue(startDateTime.getNumericValue() + starttimeZoneOffSet);

 

SystemsGo_0-1671544708041.png

SystemsGo_1-1671544716930.png

 

SystemsGo_2-1671544724389.png

 

 

7 REPLIES 7

SystemsGo
Tera Contributor

 Hi Ruchit,

 

What we have done is the same. We integrate the customer's timezone from sharepoint.

 

But the time fill in servicenow is not from the form directly. The time set in ServiceNow by code. So I need some timezone convert.

SystemsGo
Tera Contributor

Hi All,

Thank you for your reply.

This issue has been resolved. with the following code.

 

function getDiffwithCustomerTimeZone(dt,strdt){
var zDateTime = new GlideDateTime();
zDateTime.setDisplayValue(strdt);
zDateTime.setTZ(tz);
var timeZoneOffSet = dt.getTZOffset();
var ztimeZoneOffSet = zDateTime.getTZOffset();
var diff = ztimeZoneOffSet-timeZoneOffSet;
dt.setNumericValue(dt.getNumericValue()-diff);
return dt;
}