有没有办法将自然语言日期NSString转换为NSDate [英] Is there a way to convert a natural language date NSString to an NSDate

查看:80
本文介绍了有没有办法将自然语言日期NSString转换为NSDate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说我有NSString @明天

Say I have the NSString @"tomorrow"

是否有任何带有此类字符串的库并将它们转换为NSDates?我想象/希望这样的事情:

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.

推荐答案

你的意思是像 dateWithNaturalLanguageString:

从链接:


dateWithNaturalLanguageString:

dateWithNaturalLanguageString:

创建并返回一个NSDate对象,该对象设置为给定字符串指定的日期和时间。

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

+(id)dateWithNaturalLanguageString :(NSString *)string

+ (id)dateWithNaturalLanguageString:(NSString *)string

包含日期口语规范的字符串,例如晚餐上周二,2001年12月31日下午3点, 12/31/01,或31/12/01。

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."

这篇关于有没有办法将自然语言日期NSString转换为NSDate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆