简体   繁体   中英

how to get dates from text in c#

From a document I want to find and get the dates, and the date will be in a different format in each document. How do I achieve that in C#?

You should rather have a look at using DateTime.TryParse Method or DateTime.TryParseExact Method

DateTime.TryParse Method Converts the specified string representation of a date and time to its DateTime equivalent and returns a value that indicates whether the conversion succeeded.

DateTime.TryParseExact Method 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.

Use DateTime.ParseExact(string, format) to create a DateTime from a formatted string.

Check out http://www.codeproject.com/KB/cs/String2DateTime.aspx for more details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM