Unable to parse string to DateTime

346 views Asked by At

I have this string:

Fri, 13 Jan 2012 04:26:42 PST

I tries to parse it like that:

DateTime.TryParse("Fri, 13 Jan 2012 04:26:42 PST", out date)

Or like that:

Convert.ToDateTime("Fri, 13 Jan 2012 04:26:42 PST")

And it throws to me:

MESSAGE: The string was not recognized as a valid DateTime. There is an unknown word starting at index 26.

Any idea what is wrong and how can I fix it?

2

There are 2 answers

0
Oded On BEST ANSWER

With named timezones, you can create a dictionary that maps the names to the actual timezone difference in the format recognized - then, use this dictionary to replace named timezones with their recognized format.

At this point you will have a string that can be parsed by the framework.

Dictionary<string,string> namedToActualTZ = new Dictionary<string,string>();
namedToActualTZ.Add("PST", "-0800");
0
msk On

its impossible to do it by default function such as , convert , format .. etc.you should write a function to parse it manualy.in it ,extract the weekday & time & date ... then create a valid date string or directly a date variable.