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.