posts - 66,comments - 41,trackbacks - 0

//比较DateTime类型
   DateTime dt1=DateTime.Now;
   DateTime dt2=Convert.ToDateTime ("2006-11-09 18:04:11");
  
   if(dt1.CompareTo (dt2)< 0)  //CompareTo:0-两者相等
    Response.Write ("<script>alert(\"dt1<dt2\");</script>");
   else
    Response.Write ("<script>alert(\"dt1>dt2\");</script>");

   
   //比较string
   DateTime dt3=DateTime.Now ;
   string strdt3=dt3.ToString ("yyyy-MM-dd HH:mm:ss");
   string strdt4="2006-11-09 18:04:11";
     
   //字符串比较时,主要把时间都转换成yyyy-MM-dd HH:mm:ss的格式
   if (strdt3.CompareTo(strdt4)<0)//CompareTo:0-两者相等
    Response.Write ("<script>alert(\"strdt3<strdt4\");</script>");
   else
    Response.Write ("<script>alert(\"strdt3>strdt4\");</script>");


文章来源:http://www.my1984.net/?action=show&id=79

MSN:
posted on 2008-05-27 10:31 kylixlu 阅读(2899) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: