Converts local time to UTC.
[Visual Basic] Public Function ToUniversalTime() As DateTime [C#] public DateTime ToUniversalTime(); [C++] public: DateTime ToUniversalTime(); [JScript] public function ToUniversalTime() : DateTime;
A new DateTime obtained by calculating the difference between UTC and local time and adding the result to or subtracting it from the current DateTime.
Exception Type | Condition |
---|---|
ArgumentOutOfRangeException | If the universal time is less than zero. |
The ToUniversalTime method creates a new DateTime object by converting this DateTime object to the coordinated universal time (UTC) time zone (see GetUTCOffset).
Note The local time is equal to UTC plus the offset.
ToUniversalTime calculates the difference between the local time (the time zone of the current thread) and UTC and adds the result to or subtracts it from the current DateTime. For example, if UTC is five hours ahead of the local time, then the return value will be five hours ahead of the value of the current DateTime object.
DateTime Structure | DateTime Members | System Namespace | TimeZone | DateTimeFormatInfo | UTF7Encoding | UTF8Encoding | System.DirectoryServices.IADsPropertyValue.UTCTime