Convert DateTime to Coordinated Universal Time (UTC) in CSharp

Description

The following code shows how to convert DateTime to Coordinated Universal Time (UTC).

Example


using System;/*  ww w .j a  v  a2 s . c  om*/

public class Example
{
   public static void Main()
   {
      DateTime date1 = new DateTime(2014, 3, 21, 2, 0, 0);

      Console.WriteLine(date1.ToUniversalTime());
      Console.WriteLine(TimeZoneInfo.ConvertTimeToUtc(date1));

      TimeZoneInfo tz = TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time");  
      Console.WriteLine(TimeZoneInfo.ConvertTimeToUtc(date1, tz));     
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var