Datetime增加Between方法

This commit is contained in:
FalconFly 2024-03-22 16:20:56 +08:00
parent 5b7a438725
commit 4566a84d96

View File

@ -137,6 +137,18 @@ namespace Falcon.SugarApi
public static string ToDateTime(this DateTime date) => date.ToString("yyyy-MM-dd HH:mm:ss");
#endregion
/// <summary>
/// 时间是否处于某个时间段内
/// </summary>
/// <param name="dt">要判断的时间</param>
/// <param name="start">开始时间</param>
/// <param name="end">结束时间</param>
/// <returns>True是False否</returns>
public static bool Between(this DateTime? dt,DateTime start,DateTime? end = null) {
end ??= DateTime.Now;
return dt > start && dt <= end;
}
}
/// <summary>