Determines whether two object instances represent the same time (have same hour/minute/second values). - CSharp System

CSharp examples for System:DateTime Second

Description

Determines whether two object instances represent the same time (have same hour/minute/second values).

Demo Code


using System.Globalization;
using System;//  w  w w . ja  v  a2  s  . c o m

public class Main{
        /// <summary>
    ///   <para>Determines whether two <see cref="DateTime"/> object instances represent the same time (have same hour/minute/second values).</para>
    /// </summary>
    /// <param name="self">Current date to compare with the second.</param>
    /// <param name="other">Second date to compare with the current.</param>
    /// <returns><c>true</c> if both <paramref name="self"/> and <paramref name="other"/> have equal time component.</returns>
    /// <seealso cref="IsSameDate(DateTime, DateTime)"/>
    public static bool IsSameTime(this DateTime self, DateTime other)
    {
      return self.Second == other.Second && self.Minute == other.Minute && self.Hour == other.Hour;
    }
}

Related Tutorials