CSharp - Write program to Get Current Date Time In Universal Time Coordinated (UTC)

Requirements

You will need to get the current date and time in UTC.

Hint

You can use DateTimeOffset that contain time zone information in addition to the date and time.

Demo

using System;
class Program/*  w ww  .  ja  v  a2 s  .c o  m*/
{
    static void Main(string[] args)
    {
        // Current time serves as input 
        DateTime now = DateTime.Now;
        DateTime utcNow = DateTime.UtcNow;
        DateTimeOffset completeInstant = DateTimeOffset.Now;
        DateTimeOffset utcCompleteInstant = DateTimeOffset.UtcNow;

        // Outputs 
        Console.WriteLine("Now: " + now);
        Console.WriteLine("UTC now: " + utcNow);
        Console.WriteLine("Now (including time zone): " + completeInstant);
        Console.WriteLine("Time zone (offset against UTC): " + completeInstant.Offset.TotalHours);
        Console.WriteLine("UTC now (including time zone): " + utcCompleteInstant);
    }
}

Result