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