Convert YYYYMMDD string date to a datetime value

http://stackoverflow.com/questions/8206827/convert-yyyymmdd-string-date-to-a-datetime-value 
var newDate = DateTime.ParseExact("20111120", "yyyyMMdd", CultureInfo.InvariantCulture);

OR

string str = "20111021"; string[] format = {"yyyyMMdd"}; DateTime date; if (DateTime.TryParseExact(str, format, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.None, out date)) { //valid }

你可能感兴趣的:(Convert YYYYMMDD string date to a datetime value)