This documentation is archived and is not being maintained.

SPTimeZone.LocalTimeToUTC Method

Windows SharePoint Services 3

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

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

public DateTime LocalTimeToUTC(
	DateTime date


Type: System.DateTime
A System.DateTime object that represents the local date and time value to convert.

Return Value

Type: System.DateTime
A System.DateTime object that contains the date converted to UTC.

The following code example converts a date and time value to UTC and displays the converted value.

using (SPSite oSiteCollection = new SPSite("http://localhost"))
    using (SPWeb oWebsite = oSiteCollection.AllWebs["Website_Name"])
        SPRegionalSettings oRegionalSettings = oWebsite.RegionalSettings;
        SPTimeZone oTimeZone = oRegionalSettings.TimeZone;
        System.DateTime dtDateNew = new System.DateTime(2007, 7, 15, 9, 5, 30, 0);

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.