无法将字符串识别为有效的DateTime。在Windows Server 2012上使用ParseExact

用户名

我正在尝试使用“ en-CA”文化信息将字符串解析为一个日期。它在Windows Server 2008 R2上运行良好,但在Windows Server 2012中显示异常:-无法将字符串识别为有效的DateTime。

以下是代码段:-

 DateTime tvDefaultDate = DateTime.ParseExact("31/12/9999", "dd/MM/yyyy", 
                                                      new CultureInfo("en-CA"));
马克·格雷维尔(Marc Gravell)

/在这里,简单地DateTimeFormatInfo.DateSeparator用数字,表示“千位分隔符”(不是逗号)和.用“十进制分隔符”(不是句点)来表示“日期分隔符”()。

在en-CA中,分隔符映射到-日期需要是31-12-9999要使用文字/而不是日期分隔符,您需要对其进行转义:

DateTime tvDefaultDate = DateTime.ParseExact("31/12/9999", @"dd\/MM\/yyyy",
        new CultureInfo("en-CA"));

另外,也可以使用不变文化。不变文化/用于日期分隔符。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Datetime.ParseExact“无法将字符串识别为有效的DateTime”错误

无法将字符串识别为DateTime.ParseExact的有效参数

使用DateTime.ParseExact C#无法将字符串识别为有效的DateTime

尝试使用linq筛选数据时,无法将字符串识别为有效的DateTime

DateTime.ParseExact:“字符串未被识别为有效的DateTime”

具有“ 3”参数的powershell“ ParseExact”:“未将字符串识别为有效的DateTime

在ParseExact中,毫秒未将字符串识别为有效的DateTime

DateTime.ParseExact:字符串未被识别为有效的日期时间

DateTime.ParseExact无法识别为有效的DateTime

使用ViewState字符串未被识别为有效的日期时间

无法将字符串识别为Datetime的有效解析字符串

使用“2”个参数调用“Parse”的解析异常:“字符串未被识别为有效的日期时间。”

无法将字符串识别为有效的DateTime“格式dd / MM / yyyy”

无法将字符串识别为有效的DateTime格式异常

无法将字符串识别为有效的DateTime c#

解析时无法将字符串识别为有效的DateTime

无法将字符串识别为有效的DateTime

Windows Server 2016上将字符串识别为无效的Datetime

Windows Server 2012上Add-LocalGroupMember无法识别为cmdlet,function,脚本或文件

itertools无法将numpy ints识别为Python 3.6上的有效输入

使用SSIS将CSV文件导入SQL Server时,从字符串中删除空格的最有效方法是什么?

使用100%CPU的SQLServer.exe(在Windows Server 2012上)

无法将字符串识别为有效的DateTime。2015年6月26日

无法在Windows Server 2012上安装SQL Server 2012

C#和SQL Server在字符串是否有效的Base64上存在分歧-正确吗?

Matplotlib上的Latex无法识别为字符串

使用 ParseExact 遇到 String 未被识别为有效日期时间

在C#中无法将字符串识别为有效的日期时间

将字符串转换为日期获取(未将字符串识别为有效的DateTime)