解析 11/06/2020 - 18:13 到日期时间

spe*_*pez 0 c# datetime

我正在尝试将以下格式解析为日期时间:

11/06/2020 - 18:13
Run Code Online (Sandbox Code Playgroud)

我试过:

DateTime t= DateTime.ParseExact(data[i][j], "dd/MM/yyyy - hh:mm", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)

但它给出了例外:

System.FormatException: 'String 未被识别为有效的 DateTime。'

AAA*_*ddd 5

您需要指定 24 小时制时间 HH

DateTime.ParseExact(input, "dd/MM/yyyy - HH:mm", CultureInfo.InvariantCulture);
Run Code Online (Sandbox Code Playgroud)

“HH”自定义格式说明符

“HH”自定义格式说明符(加上任意数量的附加“H”说明符)将小时表示为从 00 到 23 的数字;也就是说,小时由从零开始的 24 小时制表示,该时钟计算自午夜以来的小时数。一位数的小时使用前导零进行格式化。