c# - Error while converting String with DateTime.ParseExact() function -
i trying convert string value in date time. know question asked many times. checked answers. didn't answer problem.
following code:
string objtime = "5/4/2013 10:30 pm"; datetime d = datetime.parseexact(objtime, "dd/mm/yyyy h:mm", cultureinfo.currentculture);
i have checked chenging system datetime format.
and have use this:
datetime d = datetime.parseexact(objtime, "d/m/yyyy h:mm tt", cultureinfo.currentculture);
can 1 please me solve problem?
and have check changing format d/m/yyy h:mm
still giving me error. using visual studio 2012
.
your string has day , month in single digit, , trying parse format supports double digits day/month
you should do:
string objtime = "5/4/2013 10:30 pm"; datetime d = datetime.parseexact(objtime, "d/m/yyyy h:mm tt", cultureinfo.currentculture);
you should use single d
, m
, support single digit , double digit day/month parsing.
you should use lower case h
since have pm
in string. final format should "d/m/yyyy h:mm tt"
Comments
Post a Comment