UTC字符串日期时间异常字符串、异常、日期、时间

由网友(万水千山奔波)分享简介:我收到此异常:String was not recognized as a valid DateTime该字符串:2012-10-03T10:41:22.988401+01:00使用此code:using this code:DateTime.ParseExact(TheStringAbove, "o", Cu...

我收到此异常:

String was not recognized as a valid DateTime

该字符串:

2012-10-03T10:41:22.988401+01:00

使用此code:

using this code:

DateTime.ParseExact(TheStringAbove, "o", CultureInfo.InvariantCulture, DateTimeStyles.None);

我知道,日期时间字符串的UTC。这有什么不对的code?谢谢你。

I know that the DateTime string is UTC. Is there anything wrong with the code? Thanks.

推荐答案

该字符串的没有的UTC - 这是显式得到的东西说这是提前半小时UTC的!这正是+01:00表示。你真的需要考虑仔细的那部分。

That string is not UTC - it's explictly got something saying it's an hour ahead of UTC! That's what the +01:00 means. You really need to think about that part carefully.

它之所以失败是并不完全符合 O格式:

The reason it's failing is that doesn't quite conform to the "o" format:

在O或O标准格式说明对应于'。'YYYY - - MMdd'T'HH:毫米'SS fffffffK自定义格式字符串DATETIME值

The "O" or "o" standard format specifier corresponds to the "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffK" custom format string for DateTime values

请注意,有7 FS有,但你只得到了6位小数。 2012-10-03T10:41:22.9884010 + 01:00 工作正常 - 但你仍然需要检查是否它实际上意味着你想它的意思是,依据是什么您的期望,这实在是UTC。

Note that there are 7 fs there, but you've only got 6 decimal places. 2012-10-03T10:41:22.9884010+01:00 works fine - but you'll still need to check whether it actually means what you want it to mean, based on your expectation that this is really UTC.

阅读全文

相关推荐

最新文章