C# TimeZoneInfo ConvertTimeToUtc(DateTime)

Description

TimeZoneInfo ConvertTimeToUtc(DateTime) converts the specified date and time to Coordinated Universal Time (UTC).

Syntax

TimeZoneInfo.ConvertTimeToUtc(DateTime) has the following syntax.


public static DateTime ConvertTimeToUtc(
  DateTime dateTime
)

Parameters

TimeZoneInfo.ConvertTimeToUtc(DateTime) has the following parameters.

  • dateTime - The date and time to convert.

Returns

TimeZoneInfo.ConvertTimeToUtc(DateTime) method returns The Coordinated Universal Time (UTC) that corresponds to the dateTime parameter. The DateTime value's Kind property is always set to DateTimeKind.Utc.

Example

The following example illustrates the conversion of time values whose Kind property is DateTimeKind.Utc, DateTimeKind.Local, and DateTimeKind.Unspecified, respectively. It also illustrates the conversion of ambiguous and invalid times.


/*from w w w  . j a  v a  2  s  . c  o m*/
using System;
public class MainClass{
  public static void Main(String[] argv){  
    DateTime datNowLocal = DateTime.Now;
    Console.WriteLine("Converting {0}, Kind {1}:", datNowLocal, datNowLocal.Kind);
    Console.WriteLine("   ConvertTimeToUtc: {0}, Kind {1}", 
                      TimeZoneInfo.ConvertTimeToUtc(datNowLocal), 
                      TimeZoneInfo.ConvertTimeToUtc(datNowLocal).Kind);

  }
}
    

The code above generates the following result.





















Home »
  C# Tutorial »
    System »




Array
BitConverter
Boolean
Byte
Char
Console
ConsoleKeyInfo
Convert
DateTime
DateTimeOffset
Decimal
Double
Enum
Environment
Exception
Guid
Int16
Int32
Int64
Math
OperatingSystem
Random
SByte
Single
String
StringComparer
TimeSpan
TimeZone
TimeZoneInfo
Tuple
Tuple
Tuple
Type
UInt16
UInt32
UInt64
Uri
Version