I'm using Web API to query Twitter's REST api and I'm trying to parse the created_at
value to a DateTime
using DateTime.ParseExact(...)
:
CreatedAt = DateTime.ParseExact(tweet["created_at"],
"ddd MMM dd HH:mm:ss K yyyy",
CultureInfo.InvariantCulture,
DateTimeStyles.AdjustToUniversal)
I get the following exception:
The best overloaded method match for 'System.DateTime.ParseExact(string, string, System.IFormatProvider, System.Globalization.DateTimeStyles)' has some invalid arguments.
An example value of tweet["created_at"]
is : Wed Feb 15 19:06:56 +0000 2017
答案 0 :(得分:3)
请尝试
CreatedAt = DateTime.ParseExact(tweet["created_at"].ToString(),
"ddd MMM dd HH:mm:ss K yyyy",
CultureInfo.InvariantCulture,
DateTimeStyles.AdjustToUniversal)
问题不在于格式错误,进入ParseExact的参数是错误的,所以我的猜测是tweet []不会返回字符串类型。< / p>
答案 1 :(得分:0)
Convert.ToDateTime(doc["date"].ToString())
会起作用