C# 试图解析在上创建的twitter api时,DateTime.ParseExact()引发异常
我正在使用Web API查询Twitter的REST API,并尝试使用C# 试图解析在上创建的twitter api时,DateTime.ParseExact()引发异常,c#,datetime,asp.net-web-api,twitter,C#,Datetime,Asp.net Web Api,Twitter,我正在使用Web API查询Twitter的REST API,并尝试使用DateTime将created_at值解析为DateTime。ParseExact(…): 我得到以下例外情况: 与“System.DateTime.ParseExact(string,string,System.IFormatProvider,System.Globalization.DateTimeStyles)”匹配的最佳重载方法具有一些无效参数 tweet[“created_at”]的示例值是:Wed Feb 15
DateTime将created_at
值解析为DateTime
。ParseExact(…)
:
我得到以下例外情况:
与“System.DateTime.ParseExact(string,string,System.IFormatProvider,System.Globalization.DateTimeStyles)”匹配的最佳重载方法具有一些无效参数
tweet[“created_at”]
的示例值是:Wed Feb 15 19:06:56+0000 2017请尝试
CreatedAt = DateTime.ParseExact(tweet["created_at"].ToString(),
"ddd MMM dd HH:mm:ss K yyyy",
CultureInfo.InvariantCulture,
DateTimeStyles.AdjustToUniversal)
问题不在于格式错误,而是进入ParseExact的参数错误,所以我猜tweet[]不会返回字符串类型
Convert.ToDateTime(doc[“date”].ToString())
它会起作用的
谢谢,仅此而已。我遇到了同样的问题&结果证明我不需要费心解析日期、int或decimal——它在不解析日期、int或decimal的情况下工作。下面的解决方案将其转换为字符串,然后再次返回,所以可能它已经是一个可识别的日期时间开始。
CreatedAt = DateTime.ParseExact(tweet["created_at"].ToString(),
"ddd MMM dd HH:mm:ss K yyyy",
CultureInfo.InvariantCulture,
DateTimeStyles.AdjustToUniversal)