What’s Going On Here?It’s a little weird how hard it is to find some detailed descriptions on how SharePoint handles time, and time zones. So here’s a dump on a lot of things time and time zone related to better help you troubleshoot and predict behavior.
How Time Is StoredFields like created/modified are stored will all other list item properties in the dbo.AllUserData table as tp_Modified and tp_Created. Like all list items, events are stored in this table as well.
Time Calculation With Respect to Time ZonesTime gets stored using the clock of the machine, this is not influenced by the time zone of the machine. If the clock on the server is off, the time stored is off by the amount of the clock skew. Changing the time zone of the server (OS) doesn’t affect how time is stored. This is true for most applications.
If a server is at 6pm PST (Pacific) and you change the time zone to EST (Eastern) sure the time looks like it changes from 6pm PST to 9pm EST, but those times are equivalent. 9pm EST is just another way of writing 6pm PST. Events taking place in California are really happening at the exact same time in New York, their citizens just happen to format time differently. Time zones are just another way of expressing (formatting) the current time. To be clear. There is only one time, there are many time formats…and there is no spoon.
The Clock IS Important Though
If you change the time on the server (OS) clock you’ll change how time will get stored (for new edits/additions). In this case you’ve actually had an impact on time. Namely because going from 6pm PST to 7pm PST means someone actually lost an hour they’ll never get back (not that fake ones you tell yourself about when you travel through different time zones). By changing the clock from 6pm PST to 7pm PST, you’ve effectively moved the server through time. As a result, this will effect the times that items are recorded to be stored at.
How Time Zones Get SetBy default all your users see the time as it is formatted at the root site (SPWeb) level. These settings get set when the site collection is provisioned by the web application default time zone (Figure 1 shown below). These settings get copied down when new sub sites are provisioned under the root site. Finally, if any user doesn’t like the way dates and times are displayed, they can override how time is presented to them using their personal regional settings (Figure 2 also below). But most of the time its the root site settings time zone that users are complaining about.
Default Site (SPWeb) Time ZonesThis setting dictates the formatting/time zone for all data in the site. By default these get copied down from the parent web at time of creation. You can view/change these settings (if you’re a Site Administrator) by going to:
- Site Actions->Site Settings
- Click on Regional Settings
Changing the Regional Settings time zone for a web programmatically looks like the code below. Time zone IDs come from a list of known time zones.
using (SPSite siteCollection = new SPSite("http://localhost"))
using(SPWeb websiteRoot = siteCollection.RootWeb)
SPRegionalSettings regionalSettings = websiteRoot.RegionalSettings;
SPTimeZone timeZoneIndianaEast = regionalSettings.TimeZones;
regionalSettings.TimeZone.ID = timeZoneIndianaEast.ID;
User Site Collection Time ZonesWe say user site collection time zones settings because even though this is stored per user, these settings reset in across site collections. Just because you’ve set this in site collection A doesn’t have any impact on site collection B. It will follow you around across many sites (SPWeb) within a site collection though.
You can override the default site time zone by going to:
- Click on your username in the header and click on My Settings.
- Click on My Regional Settings.
- Uncheck Always follow web settings and override the time zone with one of your preference for this site collection.
overriding the default time zone
You can change this for a given user with the following code:
//Create a new regional settings based off of the current web.
SPRegionalSettings regionalSettings = new SPRegionalSettings(web, true);
//Set some settings
SPTimeZone timeZoneIndiaEast = regionalSettings.TimeZones;
regionalSettings.TimeZone.ID = timeZoneIndiaEast.ID;
//Assign to user and update.
user.RegionalSettings = regionalSettings;
FalloutThere are some interesting effects of the time zone settings. For instance, if you ship a site collection to another time zone, it will still behave as if it’s in your original time zone with no difference at all so long as the clock at the host is the correct time.
Different users can have very different time settings across different site collections. The good news is that they get the final say on how time is formatted.
Both these settings can be manipulated programmatically. When these settings are set appropriately they can help users from very different time zones collaborate on data with time formatted in a way that make sense to them. This especially applies to event/calendar items.
Hope that helps someone, regional settings can have a big impact on collaboration projects.