DateTime - IsNow
A DateTime extension method that query if '@this' is now.
public static void Main() { DateTime date1 = DateTime.Now; DateTime date2 = new DateTime(2006, 7, 25, 10, 45, 09); Display(date1); Display(date2); } public static void Display(DateTime date) { // C# Extension Method: DateTime - IsNow if(date.IsNow()) { Console.WriteLine("{0, 40}: It's equal to DateTime.Now.", date.ToFullDateTimeString()); } else { Console.WriteLine("{0, 40}: It's not equal to DateTime.Now.", date.ToFullDateTimeString()); } }
View Source
using System; public static partial class Extensions { /// <summary> /// A DateTime extension method that query if '@this' is now. /// </summary> /// <param name="this">The @this to act on.</param> /// <returns>true if now, false if not.</returns> public static bool IsNow(this DateTime @this) { return @this == DateTime.Now; } }