【发布时间】:2015-02-23 06:14:32
【问题描述】:
在我开始解释之前,我需要告诉我我已经尝试了 stackoverflow 中提供的所有可能的解决方案。但在 Windows 7 中不起作用。
在 Windows 7 上解析日期时间不起作用。 我试过下面的代码sn-ps
DateTime.ParseExact(arr[TransactionDateIndex], "M/dd/yyyy h:mm:ss tt", null);
DateTime.ParseExact(arr[TransactionDateIndex], "M/d/yyyy h:mm:ss tt",CultureInfo.InvariantCulture);
DateTime.Parse(DateTime.Parse(arr[TransactionDateIndex]).ToString("M/d/yyyy h:mm:ss tt"),CultureInfo.InvariantCulture);
我有一个输入文件,它有一个交易日期列,它可以是任何有效的日期时间格式,现在在文件中它的 (MM/dd/YYYY) 我需要转换为“M/d/ yyyy h:mm:ss tt" 格式。
在 XP 中运行时,此代码运行良好,但在 Windows 7 中,即使在尝试 ParseExact 后也会显示错误。
即使我使用
if (DateTime.TryParse(input, out dateTime))
{
}
在 Windows 7 中运行时,很少有记录会被视为无效,但在 XP 中会解析相同的内容。
【问题讨论】:
-
在日期时间解析中,您提供要解析的格式,而不是要解析的格式。
-
没有看到失败的输入数据,这里我无话可说。
-
但是“yyyy-MM-dd”也可以。
标签: c# datetime windows-7 datetime-parsing