An api im using is providing me a date. This date is of type string and is presented in the format:
Mon Nov 16 19:15:09 +0000 2009
DateTime.TryParse() fails when this value is provided. Can anyone point me in the right direction?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Using the
DateTimeOffsetclass in order to handle the offset.Change the offset in the string – e.g. ‘0600’ and then change the offset assertion to match, it’ll work.
You can then convert this into a
DateTimeif you have to – but you lose the offset information; so you have to decide whether you’re going to keep it as the original local time (19:15:09), or if you’re going to convert to some standard time (e.g.13:19:05 UTCif offset is+06:00).It gets interesting if you need to convert that to your own local time – because it would depend on what DST rules were in place in 2009 at that time of the year – that can cause a real headache!
So, if you’re going to
DateTimeI recommend converting to universal time and then go from there. Add this to the test:This outputs: