ISO8601格式的字符串转换为DateTime [英] ISO8601 formatted string to DateTime

查看:78
本文介绍了ISO8601格式的字符串转换为DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我具有以下ISO8601格式的日期时间字符串:

I have the following ISO8601 formatted date time string:

2016-03-28T16:07:00 + 0200

我想将其转换为C# DateTime 对象,但是我使用的解析方法会引发异常.

I want to convert it into a C# DateTime object, but the parsing method I'm using throws an exception.

当前,我有这个:(不起作用)

string format = "yyyy-MM-ddTHH:mm:ss+zzzz";
CultureInfo provider = CultureInfo.InvariantCulture;

// Throws the exception: "String was not recognized as a valid DateTime."
DateTime time = DateTime.ParseExact("2016-03-28T16:07:00+0200", format, provider);

如何使解析函数与我的字符串配合使用?

How do I get the parse function to work with my string?

推荐答案

尝试 DateTime时间= DateTime.Parse("2016-03-28T16:07:00 + 0200"); .您的字符串似乎是

Try DateTime time = DateTime.Parse("2016-03-28T16:07:00+0200");. Your string seems to be a format that will be recognized by DateTime.Parse().

这篇关于ISO8601格式的字符串转换为DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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