c# - 为什么这个日期解析在 C# .net 1.1 中不起作用?

标签 c# datetime .net-1.1

private bool ValidDateCheck(){

 bool _isValid = true;
 try{
  DateTime.Parse("07/&*/2009");
  DateTime d = Convert.ToDateTime("07/&*/2009");
 }
 catch{
  _isValid = false;
 }
 return _isValid;
}

上面的代码如何不抛出异常?

最佳答案

这是来自 .NET 1.1 documentation :

The string s is parsed using the formatting information in a DateTimeFormatInfo initialized for the current culture.

This method attempts to parse s completely and avoid throwing FormatException. It ignores unrecognized data if possible and fills in missing month, day, and year information with the current time. If s contains only a date and no time, this method assumes 12 A.M. Any leading, inner, or trailing white space character in s is ignored.

Parameter s must contain the representation of a date and time in one of the formats described in the DateTimeFormatInfo topic.

我无法对此进行测试,因为我可以在 VS2008 中构建的最早版本是 2.0。

关于c# - 为什么这个日期解析在 C# .net 1.1 中不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1614926/

相关文章:

python - 在 Python 中表示三个字母月份的日期格式

.net - 是否有针对 .NET 1.1 与 VS 2008 的插件?

asp-classic - asp 会在.net 1.1 框架中运行吗?

C# - 更改任务栏的图标

c# - 在 C# 中,如果我的对象支持该接口(interface),我如何检查 T 是否属于 IInterface 类型并强制转换为该类型?

c# - 通过 TemplateBinding 添加 RoutedEvent

python - 如何将多个 python 日期时间实例格式化为简单格式?

php - "datetime-local"空输入导致MySQL查询失败

c# - 正则表达式匹配 C# 中的路径

c# - 如何在更新属性时调用代码隐藏中的方法?