SPTimeZone.UTCToLocalTime Method
Converts the specified DateTime value from Coordinated Universal Time (UTC) to local time.
Assembly: Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online
[SecurityPermissionAttribute(SecurityAction.Assert, UnmanagedCode = true)] public DateTime UTCToLocalTime( DateTime date )
Parameters
- date
- Type: System.DateTime
Return Value
Type: System.DateTimeA 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) + "<BR>"); } } }
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. |
Note