开发者

How to parse string into date time format?

开发者 https://www.devze.com 2023-04-06 11:31 出处:网络
I have string having value \"August-25-2011\". How开发者_Go百科 can I parse that into Datetime format?Try:

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号