Table of Contents

ConvertToUtc Method

Definition

Namespace
Tyne
Assembly
Tyne.Core.dll

Methods

| Edit this page View Source

ConvertToUtc(DateTime, TimeZoneInfo)

Converts a sourceDateTime in the sourceTimeZone into a DateTime.

Declaration
public static DateTime ConvertToUtc(this DateTime sourceDateTime, TimeZoneInfo sourceTimeZone)
Parameters
sourceDateTime
DateTime

A local DateTime. This may be Local or Unspecified. An ArgumentException will be thrown if it is Utc.

sourceTimeZone
TimeZoneInfo

The TimeZoneInfo which the sourceDateTime is in.

Returns
DateTime

A UTC DateTime from sourceDateTime.

Remarks

This returns a DateTime, which loses any offset context. Consider using ConvertToUtcAsOffset(DateTime, TimeZoneInfo) to return a DateTimeOffset which retains the offset.

Exceptions
ArgumentException

When sourceDateTime is Utc.

ArgumentException

When sourceTimeZone is null.