How to I get the user's current Timezone settings via api calls / scripting?

bcronrath
Kilo Guru

I'm trying to build a record producer that uses the js function Date().getTimezoneOffset() to detect the timezone of the client regardless of their timezone preferences and apply it to their date fields they are entering.   I can get the offset just fine with the js function, however the issue I'm running into is how to apply it to the current date since they are entering it and it is being recorded according to their current timezone settings (which 99% of the time is going to end up being the system default because no one ever changes this).   Does anyone know how to get what the current offset is for a user's timezone preferences?

Best regards,

Brian

1 ACCEPTED SOLUTION

Ken_Michelson
Kilo Guru

To get the user's timezone:



var myUserObject = gs.getUser();


myUserObject.getTZ(); -- returns the timezone of the current user



to get the current time in the user's timezone:


gs.nowDateTime();



Using those along with getTimeZoneOffset() should allow you to get what you need.


View solution in original post

3 REPLIES 3

Ken_Michelson
Kilo Guru

To get the user's timezone:



var myUserObject = gs.getUser();


myUserObject.getTZ(); -- returns the timezone of the current user



to get the current time in the user's timezone:


gs.nowDateTime();



Using those along with getTimeZoneOffset() should allow you to get what you need.


Thanks Ken,



Out of curiosity, what should I look up to find this area of the wiki site?   I had looked in timezone related docs such as Using Time Zones - ServiceNow Wiki   and GlideSystem Date and Time Functions - ServiceNow Wiki     and there is no mention of this function on either of those.   Just looking to learn to fish a bit.



Best regards,


Brian


Great question. the Wiki is an interesting place. Sometimes you can search all the obvious keywords and still not find pages you KNOW you saw last week .



In this case I just knew it was under User Object.