开发者

How to check NSString to date

How can I check NSString is date or not? For example:

NSString - Jul 14 at 14.55 PM return TR开发者_Python百科UE

NSString - Talala... return False

Please help..


Assuming you're on iOS you can check that using NSDataDetector


You could use a NSDateFormatter and allow it to use an heuristic to determine if the given input string is a date or not (just call [formatter setLeninent:YES] for this). If it can create a NSDate object out of your NSString, congratulations, the string contains a date, otherwise it most likely doesn't.


You can try creating a new NSDate instance giving the NSString and check wether the result is nil or not.

NSDate

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜