asp.net 中怎样比较 datetime 类型 的大小?

2024-12-20 02:42:01
推荐回答(2个)
回答1:

//计算当前日期

DateTime CurrentDate=new DateTime();

CurrentDate=DateTime.Now;

if(CurrentDate
{

str=str+" !新";

}

如果,您只想比较日期是否相等的话,您可以用DateTime.Compare(dt1,dt2).

回答2:

看不懂可以继续问
private double DateDiff(string howtocompare, System.DateTime startDate, System.DateTime endDate)
{
double diff=0;
System.TimeSpan TS = new System.TimeSpan(endDate.Ticks-startDate.Ticks);

switch (howtocompare.ToLower())
{
case "year":
diff = Convert.ToDouble(TS.TotalDays/365);
break;
case "month":
diff = Convert.ToDouble((TS.TotalDays/365)*12);
break;
case "day":
diff = Convert.ToDouble(TS.TotalDays);
break;
case "hour":
diff = Convert.ToDouble(TS.TotalHours);
break;
case "minute":
diff = Convert.ToDouble(TS.TotalMinutes);
break;
case "second":
diff = Convert.ToDouble(TS.TotalSeconds);
break;
}

return diff;
}