比较两个时间大小

DateTime.Compare(t1,t2)比较两个日期大小,排前面的小,排在后面的大,比如:2011-2-1就小于2012-3-2
返回值小于零:  t1 小于 t2。 
返回值等于零 : t1 等于 t2。 
返回值大于零:  t1 大于 t2。 

如:

[c-sharp]  view plain copy
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Text;  
  5.   
  6. namespace ConsoleApplication1  
  7. {  
  8.     class Program  
  9.     {  
  10.         static void Main(string[] args)  
  11.         {  
  12.   
  13.             DateTime t1 = DateTime.Parse("2011-2-2");  
  14.             DateTime t2 = DateTime.Parse("2011-3-1");  
  15.   
  16.             if (DateTime.Compare(t1, t2) > 0)   
  17.                 Console.WriteLine("t1 > t2");  
  18.             if (DateTime.Compare(t1, t2) == 0)   
  19.                 Console.WriteLine("t1 == t2");  
  20.             if (DateTime.Compare(t1, t2) < 0)   
  21.                 Console.WriteLine("t1 < t2");  
  22.         }  
  23.     }  
  24. }  

运行结果:

t1 < t2
请按任意键继续. . .


转自:http://blog.csdn.net/aspnet2002web/article/details/6171415

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值