Hi,
I’m currently participating in deploying an international Sharepoint intranet which hosts teamsites where users can track tasks and knowledge. Our infrastructure is running in the GMT+1 timezone but not all of our users are in that timezone. Since Sharepoint is using web technology all users see by default GMT+1 times, which is very annoying when you are working from within another time zone.
Site Time zones
Sharepoint allows owners, of a site, to define the timezone they want for their site. This in order to see correct date and time stamps on items (eg on created and modified fields). It is recommended that the owners of the site define the timezone based on the timezone of the users who most frequently use the site.
User time zones
If the visiting user is in a different timezone as the site he can personalize the display of dates and times so it aligns with his timezone. But they need to set this for each site and they have no idea that there is a difference.
Time zone check webpart
In order to warn users that the site they are visiting does not run in the same timezone as theirs, I created a small webpart. The webpart generates some javascript that checks if the local timezone bias is different than the “context timezone” bias. The “context timezone” represents the timezone as experienced by the user visiting the site.
The code for building the webpart (this code is functional but not at the level you would expect to run on a production environment):
protected override void Render(HtmlTextWriter writer) { //initiate objects SPWeb oWebsite = SPContext.Current.Web; SPRegionalSettings oContext = SPContext.Current.RegionalSettings; //write javascript code in the webpart writer.Write("<script language='JavaScript'>"); writer.Write("var d = new Date();"); //Edit below lines to print the server and client time offset //writer.Write("document.write(\"Server time offset:" + (oContext.TimeZone.LocalTimeToUTC(DateTime.Now) - DateTime.Now).Hours.ToString() + "<br>\");"); //writer.Write("document.write(\"Client time offset:\" + d.getTimezoneOffset());"); //below line gives problems with daylight savings //writer.Write("document.write(\"Server bias offset:" + oContext.TimeZone.Information.Bias + oContext.TimeZone.Information.DaylightBias + "<br>\");"); //check if the timezone on the local machine is equal to the current WSS context timezone writer.Write("if (d.getTimezoneOffset()/60 == " + (oContext.TimeZone.LocalTimeToUTC(DateTime.Now).Hour - DateTime.Now.Hour).ToString() + ")"); writer.Write("{"); //Enable the below line if you want show an ok message when the timezones match //writer.Write("document.write(\"<b>OK</b>\");"); writer.Write("}"); writer.Write("else"); writer.Write("{"); //edit below section with the message for mismatched timezone settings writer.Write("document.write(\"<b><font style='color:red'>Warning!</font></b><br/>\");"); writer.Write("document.write(\"The website is running in:" + oContext.TimeZone.Description +"<br/>\");"); writer.Write("document.write(\"click <a href='_layouts/regionalsetng.aspx?Type=User'>here</a> to adapt your view\");"); writer.Write("}"); writer.Write("</script>"); }
The above code allows you to build the below webpart using Visual Studio.
On request I provide the webpart in a Sharepoint solution allowing you to install it on your environment.
Tags: moss, sharepoint, timezone, webpart
March 21, 2009 at 9:12 am |
Hell of a post man…Excellent.
August 1, 2009 at 10:35 am |
The code has been updated.
The original code had an issue with daylight savings.
March 1, 2010 at 12:40 pm |
Hi, I would be very grateful for a copy of the code so that I could install. Does it simple sit in a CEWP or are server side code changes required?
Regards,
David
July 15, 2011 at 8:22 pm |
The last line in your post is:
“On request I provide the webpart in a Sharepoint solution allowing you to install it on your environment.”
I couldn’t find an email address on this site, so – I’m requesting the webpart i na Sharepoint solution!!
thanks,
Peter
September 27, 2011 at 11:34 am |
Konkursy Guy…
Really good site, thank you so much for your time in writing the posts!…
December 3, 2011 at 4:39 am |
Ronald…
[…]Sharepoint timezone hell « Wim’s Blog[…]…
February 2, 2020 at 2:08 am |
buy Here pay here birmingham al
Sharepoint timezone hell | Wim’s Blog