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

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -