gpt4 book ai didi

c# - 为什么我的日期验证器不起作用?

转载 作者:行者123 更新时间:2023-12-03 20:47:19 24 4
gpt4 key购买 nike

我正在尝试使用自定义验证器来验证输入到文本框中的日期:

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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com