How to parse string into date time format?
I have string having value "August-25-2011". How开发者_Go百科 can I parse that into Datetime format?
Try:
DateTime dt = DateTime.ParseExact(
your_date,
"MMMM-dd-yyyy" ,
CultureInfo.InvariantCulture);
Try this out.
var date = DateTime.Parse("August-25-2011");
DateTime.ParseExact(
your_date,
"MMMM-dd-yyyy" ,
CultureInfo.InvariantCulture);
For TryParseExact
DateTime parsedDate;
string pattern = "MMMM-dd-yyyy" ;
DateTime.TryParseExact(dateValue, pattern, null,
DateTimeStyles.None, out parsedDate)
Converts the specified string representation of a date and time to its DateTime equivalent using the specified array of formats, culture-specific format information, and style. The format of the string representation must match at least one of the specified formats exactly. The method returns a value that indicates whether the conversion succeeded.
精彩评论