Brian McCullough (@bpmccullough) pinged me on Twitter today with a question:
. @sympmarc is this still only option fir getting users regional settings client side? Have you come across any other alternatives?
— Brian McCullough (@bpmccullough) October 3, 2017
Brian was asking about an old blog post of mine where I basically screen scraped the data: Detecting the Current User’s Regional Settings with jQuery. It worked fine in the old days, but I didn’t think it would work anymore on SharePoint Online.
It was bugging me that I couldn’t remember the answer, so I went digging into some SharePoint pages to see what I could see. In two different SharePoint Online tenants, I saw that the
_spPageContextInfoobject has the following properties:
"preferUserTimeZone": false, "userTimeZoneData": null, "userTime24": false, "webTimeZoneData": { "Description": "(UTC-05:00) Eastern Time (US and Canada)", "Bias": 300, "Id": 10, "DaylightBias": -60, "DaylightDate": { "Year": 0, "Month": 3, "DayOfWeek": 0, "Day": 2, "Hour": 2, "Minute": 0, "Second": 0, "Milliseconds": 0 }, "StandardBias": 0, "StandardDate": { "Year": 0, "Month": 11, "DayOfWeek": 0, "Day": 1, "Hour": 2, "Minute": 0, "Second": 0, "Milliseconds": 0 } }, "webTime24": false
As I recall, if the
userTimeZoneDatais not null, then the user has set their time zone themselves. If it is null, then the user is going along with the
webTimeZoneData. I don’t have an example, but I’m pretty sure you can also check
preferUserTimeZoneto see if the user wants to have her own time set.
Note that there are lots of other goodies in
_spPageContextInfoas well. The other properties which are pertinent to time zones are:
-
userTime24
– Does the user prefer 24 hour (military ) time? -
webTime24
– Does the Web display 24 hour (military ) time?
The
TimeZoneDataproperties are also quite rich, showing the time zone description, the bias from GMT, Daylight Savings Time bias (usually 60 mins, but sometimes 30 mins), when DST starts and ends.
Note that depending on the version of SharePoint you’re running, your mileage may vary.
Does anybody really know what time it is?
by Marc D Anderson via Marc D Anderson's Blog
No comments:
Post a Comment