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


    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

  • 相关阅读:
    第十四周总结
    第十三周总结
    第十一周学习总结
    《软件需求》 阅读笔记
    第十周总结
    Echarts基础
    HTML中form表单text填写内容时的约束
    代码整洁之道 阅读笔记五
    pandas中的None和NaN
    pandas中的replace用法
  • 原文地址:https://www.cnblogs.com/net-sky/p/9236531.html
Copyright © 2020-2023  润新知