To convert system time zone into users time zone (according to their country of work)

Niharika14
Tera Contributor

Hi All,

 

I want to know if there is any possible way in which system's time zone for a particular user can be converted into the time zone of his country of work. For eg. if the country of work of user is Switzerland , then date/time should be visible in that country's time zone for that user and if the user's country is China, then date/time should be visible in the time zone of China for that user.

In my case, system's time zone is Europe/Dublin.

3 REPLIES 3

JP - Kyndryl
Kilo Sage

Hi Niharika,

Users must set their required timezone in their profile.

 

JPKyndryl_0-1670357966209.png

 

Regards,
JP

Hi JP,

Actually for storing date and time , I am using string field so changing system time zone won't work here as any function tostring or getdisplayvalue returns time in gmt format, so before storing it in a string field I was thinking to convert it in user's timezone.

 

@JP - Kyndryl is not suggesting you change the system time zone.  Every user has a time zone for there account and all date/times are displayed based on that time zone.  By default the users time zone is set to the system default.  So if there time zone is set properly you can simply do 
var stringDT = someDT.getDisplayValue();

and stringDT will be the someDT translated into the time zone of the user the code was run as.

 

Otherwise you need to look at the GlideDateTime docs

https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server_legacy/c_GlideDateTimeAPI#r_...

and this post

https://www.servicenow.com/community/developer-articles/handling-time-zones-in-servicenow-timezoneut...

 

You have to use a packages call to get a time zone object and then you can convert to what ever time zone you like.