One, the form of stitching strings
DateTime DT=Convert.todatetime ("20100101". Substring (0,4)+"-"+"20100101". Substring (4,2)+"-"+"20071107". Substring (6,2));
II,convert.todatetime (String)
The string format is required and must be YYYY-MM-DD HH:MM:SS
Iii. Convert.todatetime (String, IFormatProvider)
DateTime dt;datetimeformatinfo Dtformat = new System.globalizationdatetimeformatinfo ();d Tformat.shortdatepattern = " Yyyy/mm/dd ";d t = convert.todatetime (" 2011/05/26 ", Dtformat);
Iv. Datetime.tryparse (string,out DateTime)
1, more often, will use the Datetime.tryparse (string,out datetime) method, because this method has security mechanism, when the string content is not correct, you can return the minimum value of the date MinValue. It is possible to determine the success of the conversion by returning the bool value. datetime.parseexact () needs to be converted in a specific format, with strict requirements for formatting, and an error if the string is not of the date content and the amount resembles "asdfasd".
2, after conversion with Datetime.tryparse (String,out datetime), the resulting datetime can be datetime. ToString ("ddd, MMM. DD ") to convert to a special demand format, more flexible and convenient.
Reference: Converting strings to dates in C # http://www.studyofnet.com/news/851.html
This article is from the "Learning also leisure" blog, please be sure to keep this source http://studyofnet.blog.51cto.com/8142094/1681791
How to convert a string into a date in C #