C# DateTime for Twitter API created_at field

Viewed 125

The v1 Twitter API returns created_at dates in the following format:

Mon Dec 28 11:32:24 +0000 2020

How can I parse this to a C# DateTime? I'm thinking I need to use the ParseExact method but I'm unsure what the format string should be and how I go about figuring it out

Can anyone help?

1 Answers

If you want to parse a DateTime like this with ParseExact the format string should look like the following:

System.DateTime.ParseExact("Mon Dec 28 11:32:24 +0000 2020", "ddd MMM dd HH:mm:ss zzz yyyy", null);

ddd - Abbreviated name of the Day

MMM - Abbreviated name of the Month

dd - Day of the month as number 01-31

h - hour as 12 hour clock

H - 24 hour clock

HH - 24 hour clock with leading zero

mm - minutes

ss - seconds

zzz - With DateTime values represents the signed offset of the local operating system's time zone from UTC, measured in hours and minutes.

yyyy - year

For reference, this has a comprehensive list of datetime formating: DateTime Formatting

Related