在我开始解释之前,我需要告诉我已经尝试了 stackoverflow 中提供的所有可能的解决方案。但在 Windows 7 中不起作用。
在 Windows 7 上解析日期时间不起作用。我尝试了以下代码片段
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 中会解析相同的内容。