Title: DateTime.ParseExact() throws exception when trying to parse twitter api created_at
Tags: c#;datetime;asp.net-web-api;twitter
Question: 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
Comment: Ran into the same & turned out I didn't need to bother parsing dates, int, or decimal - it worked w/o that. Solution below turns it into a string and then back out again, so maybe it was already a recognizable DateTime to start with.

Here is the accepted answer: Please try
CreatedAt = DateTime.ParseExact(tweet["created_at"].ToString(),
"ddd MMM dd HH:mm:ss K yyyy",
CultureInfo.InvariantCulture,
DateTimeStyles.AdjustToUniversal)
The problem isn't that the format is wrong, it's that the arguments going into ParseExact are wrong, so my guess would be that tweet[] doesn't return a string type.
Comment for this answer: Thanks, that's all it was.

Here is another answer: Convert.ToDateTime(doc["date"].ToString())
It will work

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 1, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2017:00:02/22/17', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c#><datetime><asp.net-web-api><twitter>', 'Title': 'DateTime.ParseExact() throws exception when trying to parse twitter api created_at', 'ViewCount': 2051, 'id': 42402337, 'user_AboutMe': '', 'user_AccountId': 1933467.0, 'user_DisplayName': 'Ian Tunbridge', 'user_Reputation': 158.0, 'user_Views': 21.0, 'user_id': 1742373.0}}