更新时间:2023-01-29 15:52:06
不要使用的CurrentCulture
- 使用固定区域性。否则,你会拿起当前区域性的日期和时间分隔符。
Don't use CurrentCulture
- use the invariant culture. Otherwise you'll be picking up the current culture's date and time separators.
此外,你需要使用 HH
而不是 HH
如您使用的是24小时制,不是一个12小时制。这工作得很好:
Also, you need to use HH
instead of hh
as you're using a 24-hour clock, not a 12-hour clock. This works fine:
using System;
using System.Collections.Generic;
using System.Globalization;
class Test
{
static void Main()
{
string date = "13/02/07,16:05:13+00";
DateTime dt = DateTime.ParseExact(date, "yy/MM/dd,HH:mm:ss+00",
CultureInfo.InvariantCulture);
Console.WriteLine(dt);
}
}
时的+00肯定总是会一样吗?如果你需要应付非零点偏置,它会改变的事情一点。
Is the "+00" definitely always going to be the same? If you need to cope with non-zero offsets, it will change things a bit.