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

Popular posts from this blog

php - mySql Join with 4 tables -

css - Text drops down with smaller window -

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -