Get the current Coordinated Universal Time (UTC) and UTC offset.
using System;
using System.Globalization;
class TimeZoneDemo
{
static void Main( )
{
const string dataFmt = "{0,-30}{1}";
const string timeFmt = "{0,-30}{1:yyyy-MM-dd HH:mm}";
TimeZone localZone = TimeZone.CurrentTimeZone;
DateTime currentDate = DateTime.Now;
DateTime currentUTC = localZone.ToUniversalTime( currentDate );
TimeSpan currentOffset = localZone.GetUtcOffset( currentDate );
Console.WriteLine( timeFmt, "Coordinated Universal Time:", currentUTC );
Console.WriteLine( dataFmt, "UTC offset:", currentOffset );
}
}
Related examples in the same category