现在的位置: 首页 > 综合 > 正文

c# 日期格式與大小判斷

2012年12月18日 ⁄ 综合 ⁄ 共 353字 ⁄ 字号 评论关闭
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   =   "错误";  
  }

抱歉!评论已关闭.