c# - Unable to create date with current time from string -


i taking selected date telerik date picker , want take selected date , current system time 24 hours format , want date this:

for ex: current date = dd/mm/yy hh:minutes:seconds

21/1/2016 14:48:21 

this code:

datetime dt = datetime.parseexact(datepicker1.selecteddate.value.toshortdatestring(), "dd/mm/yyyy", cultureinfo.invariantculture);//error:string not recognized valid datetime.  datepicker1.selecteddate.value= {1/21/2016 12:00:00 am}  datepicker1.selecteddate.value.toshortdatestring()=1/21/2016  

error:string not recognized valid datetime on datetime.parseexact.

change format in parseexact from

"dd/mm/yyyy" 

to

"m/d/yyyy" or "m/d/yyyy h:m:s tt" //the first 1 use .toshortdatestring(), second 1 1/21/2016 12:00:00 

the first 1 takes care case 21/12/1997

the second 1 takes care 12/21/1997, 2/21/1997, 12/2/1997, , 2/1/1997 in addition take care of time info

also, note may consider have multiple formats (just in case): "d/m/yyyy h:m:s", "d/m/yyyy h:m:s tt" take care of case day , month swapped , when have am/pm.

msdn link.


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -