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
Post a Comment