验证范围中日期时间的扩展方法

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了验证范围中日期时间的扩展方法相关的知识,希望对你有一定的参考价值。

This snippets regards a couple of extension methods to verify if a specified datetime is into a range.
  1. #region DATETIME
  2. /// <summary>
  3. /// Verify if a datetime is in a range
  4. /// </summary>
  5. /// <param name="dateToCompare">The date to compare</param>
  6. /// <param name="Left">The left datetime in the range</param>
  7. /// <param name="Right">The right datetime in the range</param>
  8. /// <remarks>The range will include the left and the right datetime specified</remarks>
  9. /// <returns>Returns true if the datetime compared is into the range specified</returns>
  10. public static bool BetweenInclusive(this DateTime dateToCompare, DateTime Left, DateTime Right)
  11. {
  12. bool result = (dateToCompare.CompareTo(Left) >= 0) && (dateToCompare.CompareTo(Right) <= 0);
  13. return result;
  14. }
  15.  
  16. /// <summary>
  17. /// Verify if a datetime is in a range
  18. /// </summary>
  19. /// <param name="dateToCompare">The date to compare</param>
  20. /// <param name="Left">The left datetime in the range</param>
  21. /// <param name="Right">The right datetime in the range</param>
  22. /// <remarks>The range will exclude the left and the right datetime specified</remarks>
  23. /// <returns>Returns true if the datetime compared is into the range specified</returns>
  24. public static bool BetweenExclusive(this DateTime dateToCompare, DateTime Left, DateTime Right)
  25. {
  26. bool result = (dateToCompare.CompareTo(Left) > 0) && (dateToCompare.CompareTo(Right) < 0);
  27. return result;
  28. }
  29. #endregion

以上是关于验证范围中日期时间的扩展方法的主要内容,如果未能解决你的问题,请参考以下文章

日期范围验证

如何在流明中验证日期范围

按在 Pandas 中开始和结束的日期范围扩展行

jquery 验证数值大小

需要有关日期格式和验证的伪代码的帮助

如何使用 python 在两列中扩展具有日期范围的数据框?