c# - Convert string to Datetime by TryParseExact -
how convert string datetime using tryparseexact?
for example:
datetime date; datetime.tryparseexact(stringdatetime, "yyyy.mm.dd hh:mm:ss", cultureinfo.invariantculture, datetimestyles.none, out date);
when use tryparseexact or parseexact input string must in format trying parse as. in example, if stringdatetime not in format of yyyy.mm.dd hh:mm:ss won't work i.e.
var stringdatetime = "01/01/2013 12:00:00"; datetime date; datetime.tryparseexact(stringdatetime, "yyyy.mm.dd hh:mm:ss", cultureinfo.invariantculture, datetimestyles.none, out date); // return false stringdatetime = "2013.01.01 20:00:00"; datetime.tryparseexact(stringdatetime, "yyyy.mm.dd hh:mm:ss", cultureinfo.invariantculture, datetimestyles.none, out date); // return true
Comments
Post a Comment