开发者

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 a开发者_运维百科chieve 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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜