(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)contentquot;);
//Regex dateRegex = new Regex(@"^((?!0000)[0-9]{4}-((0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-8])|(0[13-9]|1[0-2])-(29|30)|(0[13578]|1[02])-31)|([0-9]{2}(0[48]|[2468][048]|[13579][26])|(0[48]|[2468][048]|[13579][26])00)-02-29)contentquot;);
Console.WriteLine("开始日期: " + dt.ToString("yyyy-MM-dd"));
while (dt <= endDay)
{
if (!dateRegex.IsMatch(dt.ToString("yyyy-MM-dd")))
{
Console.WriteLine(dt.ToString("yyyy-MM-dd") + " false");
}
if (dt == endDay)
{
break;
}
dt = dt.AddDays(1);
}
Console.WriteLine("结束日期: " + dt.ToString("yyyy-MM-dd"));
sw.Stop();
Console.WriteLine("测试用时: " + sw.ElapsedMilliseconds + "ms");
Console.WriteLine("测试完成!");
Console.ReadLine();
DateTime dt = new DateTime(1, 1, 1); DateTime endDay = new DateTime(9999, 12, 31); Stopwatch sw = new Stopwatch(); sw.Start(); Regex dateRegex = new Regex(@"^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)contentquot;); //Regex dateRegex = new Regex(@"^((?!0000)[0-9]{4}-((0[1-9]|1[0-2])-(0[1-9]|1[0-9]|2[0-8])| (0[13-9]|1[0-2])-(29|30)|(0[13578]|1[02])-31)|([0-9]{2}(0[48]|[2468] [048]|[13579][26])|(0[48]|[2468][048]|[13579][26])00)-02-29)contentquot;); Console.WriteLine("开始日期: " + dt.ToString("yyyy-MM-dd")); while (dt <= endDay) { if (!dateRegex.IsMatch(dt.ToString("yyyy-MM-dd"))) { Console.WriteLine(dt.ToString("yyyy-MM-dd") + " false"); } if (dt == endDay) { break; } dt = dt.AddDays(1); } Console.WriteLine("结束日期: " + dt.ToString("yyyy-MM-dd")); sw.Stop(); Console.WriteLine("测试用时: " + sw.ElapsedMilliseconds + "ms"); Console.WriteLine("测试完成!"); Console.ReadLine();
view plaincopy to clipboardprint?
for (int i = 1; i < 10000; i++)
{
if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0)
{
richTextBox2.Text += string.Format("{0:0000}", i) + "\n";
}
}
for (int i = 1; i < 10000; i++) { if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) { richTextBox2.Text += string.Format("{0:0000}", i) + "\n"; } }