Open In App

DateTimeOffset.EqualsExact() Method in C#

Last Updated : 26 Feb, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

DateTimeOffset.EqualsExact(DateTimeOffset) Method is used to determine whether the current DateTimeOffset object represents the same time and has the same offset as a specified DateTimeOffset object.

Syntax: public bool EqualsExact (DateTimeOffset other);
Here, it takes the object to compare to the current DateTimeOffset object.

Return Value: This method returns true if the current DateTimeOffset object and other have the same date and time value and the same Offset value; otherwise, false.

Below programs illustrate the use of DateTimeOffset.EqualsExact(DateTimeOffset) Method:

Example 1:




// C# program to demonstrate the
// DateTimeOffset.EqualsExact(DateTimeOffset)
// Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // creating object of  DateTimeOffset
        DateTimeOffset offset1 = new DateTimeOffset(2007,
                 6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0));
  
        // creating object of  DateTimeOffset
        DateTimeOffset offset2 = new DateTimeOffset(2006,
                 6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0));
  
        // comparing two offset1 and offset2
        // instance using EqualsExact() method
        bool value = offset1.EqualsExact(offset2);
  
        if (value) 
        {
            Console.Write("offset1 is same as offset2 ");
        }
        else 
        {
            Console.Write("offset1 is not same as offset2");
        }
    }
}


Output:

offset1 is not same as offset2

Example 2:




// C# program to demonstrate the
// DateTimeOffset.EqualsExact(DateTimeOffset)
// Method
using System;
using System.Globalization;
  
class GFG {
  
    // Main Method
    public static void Main()
    {
        // creating object of  DateTimeOffset
        DateTimeOffset offset1 = new DateTimeOffset(2006,
                 6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0));
  
        // creating object of  DateTimeOffset
        DateTimeOffset offset2 = new DateTimeOffset(2006,
                 6, 1, 7, 55, 0, new TimeSpan(-5, 0, 0));
  
        // comparing two offset1 and offset2
        // instance using EqualsExact() method
        bool value = offset1.EqualsExact(offset2);
  
        if (value) 
        {
            Console.Write("offset1 is same as offset2 ");
        }
        else 
        {
            Console.Write("offset1 is not same as offset2");
        }
    }
}


Output:

offset1 is same as offset2

Reference:



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads