验证范围中日期时间的扩展方法
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了验证范围中日期时间的扩展方法相关的知识,希望对你有一定的参考价值。
This snippets regards a couple of extension methods to verify if a specified datetime is into a range.
#region DATETIME /// <summary> /// Verify if a datetime is in a range /// </summary> /// <param name="dateToCompare">The date to compare</param> /// <param name="Left">The left datetime in the range</param> /// <param name="Right">The right datetime in the range</param> /// <remarks>The range will include the left and the right datetime specified</remarks> /// <returns>Returns true if the datetime compared is into the range specified</returns> public static bool BetweenInclusive(this DateTime dateToCompare, DateTime Left, DateTime Right) { bool result = (dateToCompare.CompareTo(Left) >= 0) && (dateToCompare.CompareTo(Right) <= 0); return result; } /// <summary> /// Verify if a datetime is in a range /// </summary> /// <param name="dateToCompare">The date to compare</param> /// <param name="Left">The left datetime in the range</param> /// <param name="Right">The right datetime in the range</param> /// <remarks>The range will exclude the left and the right datetime specified</remarks> /// <returns>Returns true if the datetime compared is into the range specified</returns> public static bool BetweenExclusive(this DateTime dateToCompare, DateTime Left, DateTime Right) { bool result = (dateToCompare.CompareTo(Left) > 0) && (dateToCompare.CompareTo(Right) < 0); return result; } #endregion
以上是关于验证范围中日期时间的扩展方法的主要内容,如果未能解决你的问题,请参考以下文章