Is there a way to convert a natural language date NSString to an NSDate

Say I have the NSString @"tomorrow"

Is there any library that takes strings such as this and converts them into NSDates? I'm imagining/hoping for something like this:

NSString* humanDate = @"tomorrow at 4:15";
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"x at HH:MM"];
NSDate* date = [dateFormatter dateFromString:humanDate];

I would also want to do things like "Next monday", etc. but it doesn't have to be super sophisticated. I can enforce rules on input, but I'd like a little bit of natural language available.

My alternative is to take the string, break it up into pieces, and format it manually. But I was hoping someone has already done this.


Do you mean something like dateWithNaturalLanguageString:?

From the link:

dateWithNaturalLanguageString:

Creates and returns an NSDate object set to the date and time specified by a given string.

+ (id)dateWithNaturalLanguageString:(NSString *)string

A string that contains a colloquial specification of a date, such as “last Tuesday at dinner,” “3pm December 31, 2001,” “12/31/01,” or “31/12/01.”

链接地址: http://www.djcxy.com/p/52476.html

上一篇: python virtualenv闲置和tkinter问题

下一篇: 有没有办法将自然语言日期NSString转换为NSDate