我正在尝试使用自定义验证器来验证输入到文本框中的日期:
string CombinedDate = String.Format("{0}-{1}-{2}", txtDay.Text, txtMonth.Text, txtYear.Text);
if (DateTime.TryParseExact(CombinedDate, "dd-MM-YYYY", DateTimeFormatInfo.InvariantInfo, DateTimeStyles.None, out date))
{
args.IsValid = true;
}
else
{
args.IsValid = false;
}
但它在 21-02-2005 失败,为什么呢? 我该如何修复它
最佳答案
YYYY 必须是 yyyy
参见here对于 MSDN 中的其他格式
关于c# - 为什么我的日期验证器不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1238139/