码迷,mamicode.com
首页 > 其他好文 > 详细

DateTime.Compare(t1,t2)比较两个日期大小

时间:2018-06-28 00:52:05      阅读:137      评论:0      收藏:0      [点我收藏+]

标签:tools   rgs   collect   net   ref   details   OLE   blog   article   

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
请按任意键继续. . .

文章出处:https://blog.csdn.net/aspnet2002web/article/details/6171415

DateTime.Compare(t1,t2)比较两个日期大小

标签:tools   rgs   collect   net   ref   details   OLE   blog   article   

原文地址:https://www.cnblogs.com/net-sky/p/9236531.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!