c# - Converting string to valid DateTime -


i know there allot of questions regarding this, i've been trying day conversion work , have had no luck when applying answers same question posted here. every time try parse string datetime, "string not recognized valid datetime" exception. if use convert.todatetime, can date string, need hh:ss well.

here simplified code ruining day:

var test = "2015-05-08t05:00z";  datetime testtime = new datetime(); //testtime = convert.todatetime(test); testtime = datetime.parseexact(test, "mm/dd/yyyy hh:ss", system.globalization.cultureinfo.invariantculture);  console.writeline(testtime); 

why string not recognized valid datetime when trying convert? appreciated

try this...

var test = "2015-05-08t05:00z"; datetime testtime = new datetime(); testtime = datetime.parse(test, null, system.globalization.datetimestyles.roundtripkind);  console.writeline(testtime); console.readline(); 

or datetime.parseexact()

var test = "2015-05-08t05:00z";  datetime testtime = new datetime(); testtime = datetime.parseexact(test, "yyyy-mm-ddthh:ssz", system.globalization.cultureinfo.invariantculture, datetimestyles.roundtripkind);  console.writeline(testtime); console.readline(); 

results:

enter image description here


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -