我看到两个问题;
- 你应该使用
d
占位符而不是dd
占位符,因为你的一位数日期没有前导零。
- 没有
zzzz
作为自定义格式占位符。你应该使用zzz
占位符。
DateTime.ParseExact("Wed, 6 Mar 2019 14:39:49 +0300",
new string[] { "ddd, d MMM yyyy HH:mm:ss zzz" },
CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
But honestly, if your strings have a UTC Offset value, I would suggest parse it to DateTimeOffset
instead since a DateTime
instance does not have offset part and using zzz
specifiers is not recomended as stated on MSDN.
With DateTime
values, the "zzz" custom format specifier represents the
signed offset of the local operating system's time zone from UTC,
measured in hours and minutes. It does not reflect the value of an
instance's DateTime.Kind
property. For this reason, the "zzz" format
specifier is not recommended for use with DateTime values.
To parse DateTimeOffset
,
DateTimeOffset.ParseExact("Wed, 6 Mar 2019 14:39:49 +0300",
new string[] { "ddd, d MMM yyyy HH:mm:ss zzz" },
CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal);
Now you can use it's .DateTime
and/or .Offset
properties separately if you want.
dd
模式不匹配。"06"可能会起作用。 - haim770