Check the date difference between local date and UTC date - CSharp Language Basics

CSharp examples for Language Basics:Date Time

Description

Check the date difference between local date and UTC date

Demo Code

using System;//ww  w .  java2  s  .c o m
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   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


Related Tutorials