Compare DateTimeOffset and return the sequence in CSharp

Description

The following code shows how to compare DateTimeOffset and return the sequence.

Example


using System;//from w ww  . j a  v  a 2 s . co m

public class CompareTimes
{
   private enum TimeComparison
   { 
      Earlier = -1,
      Same = 0,
      Later = 1
   };

   public static void Main()
   {
      DateTimeOffset firstTime = new DateTimeOffset(2007, 9, 1, 6, 45, 0, 
                                 new TimeSpan(-7, 0, 0));

      DateTimeOffset secondTime = firstTime;
      Console.WriteLine("Comparing {0} and {1}: {2}", 
                        firstTime, secondTime, 
                        (TimeComparison) firstTime.CompareTo(secondTime));

        
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    Data Types »




C# Data Types
Bool
Byte
Char
Decimal
Double
Float
Integer
Long
Short
String
C# Array
Array Example
Byte Array
C# Standard Data Type Format
BigInteger
Complex
Currency
DateTime
DateTimeOffset
DateTime Format Parse Convert
TimeSpan
TimeZone
Enum
Null
tuple
var