Shortly after I replied I tried using that locale and no luck.

My code now looks like this:

NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
NSLocale *locale = [NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"];
[formatter setLocale:locale];
 NSDate *date = nil;
NSError *error = nil;
 [formatter getObjectValue:&date
                         forString:@"2013-09-08T00:36:40"
                             range:NULL
                             error:&error];
 NSLog(@"Date from String: %@", date);
NSLog(@"Error: %@", error);

Produces the following output:
2014-03-31 15:27:01.697 Untitled[30859:507] Date from String: (null)
2014-03-31 15:27:01.710 Untitled[30859:507] Error: Error
Domain=NSCocoaErrorDomain Code=2048 "The value "2013-09-08T00:36:40" is
invalid." UserInfo=0x7f89d8e04cd0 {NSInvalidValue=2013-09-08T00:36:40}


On Mon, Mar 31, 2014 at 3:21 PM, Jens Alfke <j...@mooseyard.com> wrote:

> Well, try parsing using -getObjectValue:forString:range:error: instead, so
> you get an error message.
> Also, try setting the locale of the formatter to en_US_POSIX so you don't
> get any localization effects.
> (I just got both of these suggestions from "Parsing Date Strings" in
> Apple's "Data Formatting Guide: Date Formatters". Have you read it?)
>
> --Jens




-- 
++++++++++++++++++++++++++
Diego Torres.
Phone (Mobile Germany): +49 157 30070985
Phone (Landline Chile): +56 2 29790978
Web: dtorres.me
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to