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   =   "错误";  
  }

相关文章:

  • 2021-12-23
  • 2021-06-07
猜你喜欢
  • 2022-12-23
  • 2022-01-30
  • 2022-12-23
  • 2021-10-24
  • 2022-12-23
  • 2021-11-18
相关资源
相似解决方案