为什么 DateTime.ParseExact 不解析带有尾随 Z 的 UTC 格式?
另一个 ParseExact 问题。我正在尝试将 UTC 格式的字符串解析为格式为 UTC 格式的日期时间:
"YYYY-MM-DDThh:mm:ss.ssZ"
,尾随 Z。由于某种原因无法准确解析它。我尝试过“u”、“s”、“o”自定义格式字符串,以及几种 DateTimeStyles 和手写。文化是不变的。
由于某种原因,它不喜欢 Z,Z 表示它是 UTC 字符串。当我删除它时,解析。我很高兴地,带着一些满足感,摆脱尾随的 Z,因为我知道它们是 UTC 日期时间字符串,但我不能。有什么想法吗?
Another ParseExact problem. I'm trying to parse a UTC formatted string to a datetime with the format of:
"YYYY-MM-DDThh:mm:ss.ssZ"
which is in UTC format, with the trailing Z. I can't parse exact it for some reason. I have tried the "u", "s", "o" custom format strings, as well as as several DateTimeStyles and well as handwritten. The culture is invariant.
For some reason it doesn't like the Z, which indicates it's a UTC string. When I remove it, parses. I would happily, with some satisfaction, get rid of the trailing Z as I know they are UTC datetime strings, but I can't. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您提到的格式字符串是标准格式字符串。您可能应该使用自定义格式字符串,如下所示:
如果您不这样做不要将
ToUniversalTime()
放在末尾,结果将转换为您当地的时区。The format strings you mentioned are standard format strings. You should probably use a custom format string, like this:
If you don't put
ToUniversalTime()
at the end, the result will be converted to your local time zone.