UTC字符串日期时间异常 [英] UTC string to DateTime exception

查看:124
本文介绍了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", 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.

这篇关于UTC字符串日期时间异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆