c# 日期格式與大小判斷

DateTime dt1 = DateTime.Parse("2003-3-12 18:39:00");
DateTime dt2 = DateTime.Parse("2003-3-12 18:51:00");
TimeSpan ts = dt2-dt1;
Console.WriteLine(ts.Days;);//得到天数

使用正则表达式  
   
  ^(\\d{2}|\\d{4})-((0([1-9]{1}))|(1[1|2]))-(([0-2]([1-9]{1}))|(3[0|1]))$
try  
  {  
          Datetime.Parse(textBox.Text.Trim());  
          this.Label.Text   =   "正确";  
  }  
  catch  
  {  
          this.Label.Text   =   "错误";  
  }
posted @ 2007-04-13 12:13  Nina  阅读(1638)  评论(0编辑  收藏  举报