DateTime 时间A = DateTime.Now;
DateTime 时间B = now.AddHours(1);
int result = 时间A.CompareTo(时间B);
if (result < 0)
{
//如果当前实例早于指定的日期时间,则返回小于零的值
Console.WriteLine("时间A比时间B要早");
}
else if (result == 0)
{
//如果当前实例等于指定的日期时间,则返回零
Console.WriteLine("时间A等于时间B");
}
else
{
//如果当前实例晚于指定的日期时间,则返回大于零的值
Console.WriteLine("时间A比时间B要晚");
}
比较两个时间大小 datetime
发布时间 2023-04-27 14:59:55作者: GongDonghai