SPTimeZone class

Represents the time zone setting that is implemented on a SharePoint Web site.

Inheritance hierarchy

System.Object
  Microsoft.SharePoint.SPTimeZone

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)

Syntax

'Declaration
Public Class SPTimeZone
'Usage
Dim instance As SPTimeZone
public class SPTimeZone

Remarks

Use the TimeZone property of the SPRegionalSettings class to return the time zone used in a specific site or time zone that the user has selected to view. Otherwise, use the TimeZones property of the SPRegionalSettings class to return the collection of time zone choices in the site or in the deployment of Microsoft SharePoint Foundation.

Use an indexer to return a single time zone from the collection. For example, if the collection is assigned to a variable named collTimeZones, use collTimeZones[index] in C#, or collTimeZones(index) in Visual Basic, where index is the index number of the time zone in the collection.

Examples

The following code example displays the time zone of all sites in the current site collection.

Dim siteCollection As New SPSite("https://localhost")
Dim subSites As SPWebCollection = siteCollection.AllWebs
Dim site As SPWeb
For Each site In subSites
    Console.WriteLine(site.RegionalSettings.TimeZone.Description)
Next site
using(SPSite oSiteCollection = new SPSite("https://localhost"))
{
    SPWebCollection collWebsites = oSiteCollection.AllWebs;
    foreach (SPWeb oWebsite in collWebsites)
    {
        Console.WriteLine(oWebsite.RegionalSettings.TimeZone.Description);
        oWebsite.Dispose();
    }
}

Note

Certain objects implement the IDisposable interface, and you must avoid retaining these objects in memory after they are no longer needed. For information about good coding practices, see Disposing Objects.

Thread safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See also

Reference

SPTimeZone members

Microsoft.SharePoint namespace