Re: Obtain an NSDate object from any casually entered user string
Re: Obtain an NSDate object from any casually entered user string
- Subject: Re: Obtain an NSDate object from any casually entered user string
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Thu, 15 May 2014 10:38:31 +0700
On 15 May 2014, at 02:00, Ken Thomases <email@hidden> wrote:
>
> On May 14, 2014, at 8:41 AM, Jonathan Mitchell wrote:
>
>> Is there a way to obtain an NSDate object from a casually entered user string, say: 1 1 2015 or 25 jul 15?
>>
>> I have looked at the various NSDateFormatter and NSDate API and cannot spot what I am after.
>
> You might try NSDataDetector with type NSTextCheckingTypeDate.
I did just that, and are a bit puzzled.
1. NSDataDetector recognises all date formats I encountered, which is rather good.
2. NSDataDetector ignores fractions of a second:
e.g. "2014-05-14 11:33:53.126" gets converted to: "2014-05-14 11:33:53 +0700", which in my case is not really a problem.
3. But sometimes the date of NSDataDetector is 12h ahead (again ignoring fractions of a second):
"2014-05-15 07:52:18.658" → "2014-05-15 19:52:18 +0700"
"2014-05-14 05:59:46.490 +0700" → "2014-05-14 17:59:46.490 +0700"
But not always - these work ok:
"2014-05-15 08:22:48.135"
"2014-05-15 09:15:35 +0700"
Also, all times after about 13:00 are correct.
This arbitrary advancement of 12h is obviously NOT acceptable.
What am I doing wrong?
Gerriet.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden