- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2016 12:33 PM
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
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2016 12:40 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2016 12:40 PM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2016 12:44 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-12-2016 12:47 PM
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.