日期型变量的大小比较

Datetime   rq1=Convent.ToDateTime("2005/01/01");  
  Datetime   rq2=Convent.ToDateTime("2005/02/01");  

if   (DateTime.Compare(t1,   t2)   >     0)   Console.WriteLine("t1   >   t2");    
  if   (DateTime.Compare(t1,   t2)   ==   0)   Console.WriteLine("t1   ==   t2");    
  if   (DateTime.Compare(t1,   t2)   <     0)   Console.WriteLine("t1   <   t2");  

 

 

我写的代码:

        DateTime x = DateTime.Now;
        Response.Write("<br>"+"x:"+x.ToString());
        string y = "2009-3-20";
        //string y = "3/28/2009";
        DateTime j = Convert.ToDateTime(y);
        Response.Write("<br>"+"j:"+j);
        if (DateTime.Compare(x, j) > 0)
        {

            Response.Write("x>j");

        }
        else if(DateTime.Compare(x,j)<0)
        {
            Response.Write("x小于j");
        }

posted @ 2009-03-19 14:10  双鹏  阅读(438)  评论(0编辑  收藏  举报