• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSDateFormatter not working on iOS 5.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSDateFormatter not working on iOS 5.


  • Subject: Re: NSDateFormatter not working on iOS 5.
  • From: Matt Neuburg <email@hidden>
  • Date: Fri, 11 Nov 2011 09:34:15 -0800

On Fri, 11 Nov 2011 16:13:49 +0800, Kin Mak <email@hidden> said:
>The following code used to work fine prior to iOS 5. The dateFromString method seems to stop working on iOS 5 and always returns null. I suspect this is a bug introduced in iOS 5.0. Have  anyone encountered the same issue? Or do I miss something here?
>
>		NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
>		[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS zzz"];
>
>		.....
>		//E.g currentString = @"2011-11-11 11:00:00.000 CET";
>		NSDate *date = [dateFormatter dateFromString:currentString];

It works for me if I substitute "PST" for your "CET" - could the "CET" be the problem?

I guess what I would do is start by testing whether the date formatter can round-trip its own output, like this:

    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss.SSS zzz"];
    NSString* output = [dateFormatter stringFromDate:[NSDate date]];
    NSLog(@"%@", output);

    NSDate* date = [dateFormatter dateFromString: output];
    NSLog(@"%@", date);

It can on my machine (PST). If it can't on your machine, that sounds like a bug.

Also, do try -[dateFormatter getObjectValue:forString:errorDescription:]; It is definitely throwing an error (not very helpful, "The operation couldn't be completed") for your string on my machine.

m.

--
matt neuburg, phd = email@hidden, <http://www.apeth.net/matt/>
A fool + a tool + an autorelease pool = cool!
Programming iOS 4!
http://www.apeth.net/matt/default.html#iosbook_______________________________________________

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

  • Prev by Date: Re: Lion autosave loses NSTextView position/selection
  • Next by Date: Re: Why does changing a UIScrollView's contentInset change contentOffset?
  • Previous by thread: Re: NSDateFormatter not working on iOS 5.
  • Next by thread: Re: NSDateFormatter not working on iOS 5.
  • Index(es):
    • Date
    • Thread