DateTime Comparison

When comparing two DateTime values, only their values are compared, their DateTimeKinds are ignored:


using System;
using System.Text;
class Sample
{
    public static void Main()
    {
        DateTime dt1 = new DateTime(2000, 1, 1, 10, 20, 30, DateTimeKind.Local);
        DateTime dt2 = new DateTime(2000, 1, 1, 10, 20, 30, DateTimeKind.Utc);
        Console.WriteLine(dt1 == dt2);  // True
        DateTime local = DateTime.Now;
        DateTime utc = local.ToUniversalTime();
        Console.WriteLine(local == utc);  // False
    }
}

The output:


True
False
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.