如何检查给定日期是否小于或等于当前月份。 即,任何小于或等于当前月份的日期时间都应返回 true。
最佳答案
作为扩展方法:
public static bool IsBeforeStartOfCurrentMonth(this DateTime date) {
DateTime now = DateTime.Now;
DateTime startOfCurrentMonth = new DateTime(now.Year, now.Month, 1);
return date < startOfCurrentMonth;
}
用法:
DateTime date = // some DateTime
if(date.IsBeforeStartOfCurrentMonth()) {
// do something
}
关于c# - 比较当前月份以下的日期 c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4384738/