DateTimeOffset.EqualsExact() Method in C#

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:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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");
        }
    }
}

chevron_right


Output:

offset1 is not same as offset2

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

// 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");
        }
    }
}

chevron_right


Output:

offset1 is same as offset2

Reference:



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.