判断是否正确的日期格式问题!
我想判断一个textbox里写的是不是正确的日期格式,怎么判断,谢谢!
是按照这样的格式yyyy-mm-dd
------解决方案--------------------正则表达式,也可以用js,
------解决方案--------------------^((\d{2}(([02468][048])|([13579][26]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|([1-2][0-9])))))|(\d{2}(([02468][1235679])|([13579][01345789]))[\-\/\s]?((((0?[13578])|(1[02]))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(3[01])))|(((0?[469])|(11))[\-\/\s]?((0?[1-9])|([1-2][0-9])|(30)))|(0?2[\-\/\s]?((0?[1-9])|(1[0-9])|(2[0-8]))))))
验证日期的正则,加了闰年处理。
转是博客园。
------解决方案--------------------string strMyDateTime = "2/16/1992 12:15:12 ";
// myDateTime gets Feburary 16, 1992, 12 hours, 15 min and 12 sec.
System.DateTime myDateTime =
System.DateTime.Parse(strMyDateTime);
System.IFormatProvider format =
new System.Globalization.CultureInfo( "fr-FR ", true);
// Reverse month and day to conform to a different format.
string strMyDateTimeFrench = " 16/02/1992 12:15:12 ";
// myDateTimeFrench gets Feburary 16, 1992, 12 hours,
// 15 min and 12 sec.
System.DateTime myDateTimeFrench =
System.DateTime.Parse(strMyDateTimeFrench,
format,
System.Globalization.
DateTimeStyles.NoCurrentDateDefault);
string[] expectedFormats = { "G ", "g ", "f " , "F "};
// myDateTimeFrench gets Feburary 16, 1992, 12 hours,
// 15 min and 12 sec.
myDateTimeFrench =
System.DateTime.ParseExact(strMyDateTimeFrench,
expectedFormats,
format,
System.Globalization.
DateTimeStyles.AllowWhiteSpaces);