This documentation is archived and is not being maintained.

SPTimeZone.UTCToLocalTime Method

Windows SharePoint Services 3

Converts the specified DateTime value from Coordinated Universal Time (UTC) to local time.

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

public DateTime UTCToLocalTime(
	DateTime date


Type: System.DateTime

Return Value

Type: System.DateTime
A System.DateTime structure that contains the date and time converted to their local values.

The following code example displays the date and time on which each file in a Shared Documents document library was created and last modified, converting date and time values to local time.

using (SPSite oSiteCollection = new SPSite("http://localhost"))
    using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
        SPFileCollection collFiles = oWebsite.Folders["Shared Documents"].Files;
        SPRegionalSettings oRegionalSettings = oWebsite.RegionalSettings;
        SPTimeZone oTimeZone = oRegionalSettings.TimeZone;

        foreach (SPFile oFile in collFiles)
            Console.WriteLine(oFile.Title +
            " :: " + oTimeZone.UTCToLocalTime(oFile.TimeCreated) +
            " :: " + oTimeZone.UTCToLocalTime(oFile.TimeLastModified) +

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 Best Practices: Using Disposable Windows SharePoint Services Objects.