Lenient Date Formatter
Lenient Date Formatter
- Subject: Lenient Date Formatter
- From: "Gerriet M. Denkmann" <email@hidden>
- Date: Tue, 13 May 2014 21:08:49 +0700
I need a date formatter which can do (10.9.2):
NSDate *d1 = [ dateFormatter dateFromString: @"2014-05-13 11:31:03.943 +0700" ];
NSDate *d2 = [ dateFormatter dateFromString: @"2014-05-13 11:31:03 +0700" ]; // no fractional seconds
so that both d1 and d2 are non-nil.
Is this possible?
Currently I am using this code (which works, but looks rather clumsy):
NSDateFormatter *dateFormatter1 = [ [ NSDateFormatter alloc ] init];
[ dateFormatter1 setDateFormat: @"yyyy-MM-dd HH:mm:ss ZZZ" ]; // no fractional seconds
NSDateFormatter *dateFormatter2 = [ [ NSDateFormatter alloc ] init];
[ dateFormatter2 setDateFormat: @"yyyy-MM-dd HH:mm:ss.SSS ZZZ" ];
NSDate *dat = [ dateFormatter1 dateFromString: someString ];
if ( dat == nil ) dat = [ dateFormatter2 dateFromString: someString ];
setLenient: YES seems not to be helpful.
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