Parsing DateTime to Universal Time C# -


i have xml can return time in format (7/23/2013 4:00pm) question is: how can explain datetime.parseexact i'm in "am" or in "pm"? have piece of code, returns me exception (string can not parsed)

i alredy placed example string (7/23/2013 4:00pm) in replace "pm" empty chain "".

string pattern = "mm/dd/yyyy h:mm 'utc' zzz"; datetime time = datetime.parseexact(sb.tostring(), pattern, cultureinfo.invariantculture,                                                       datetimestyles.assumeuniversal |                                                       datetimestyles.adjusttouniversal); 

thank :)

you can pass array cover various formats. use following various time inputs.

var formats = new[]      {         "m/dd/yyyy hh:mm tt",         "m/dd/yyyy hh:mmtt",         "m/dd/yyyy h:mm tt",         "m/dd/yyyy h:mmtt",         "m/dd/yyyy hhtt",         "m/dd/yyyy htt",         "m/dd/yyyy h tt",         "m/dd/yyyy hh tt"     };      var date = "7/23/2013 4:00pm";      datetime time = datetime.parseexact(date, formats, cultureinfo.invariantculture,                                                   datetimestyles.assumeuniversal |                                                   datetimestyles.adjusttouniversal); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -