Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

need help on code challenge Formatting Dates with NSDateFormatter

Instructions says: Create a date format using the given 'dateFormatter' variable to display any date with the format of '02/29/2012'. Don't worry about using it for now, just set up the formatter.

I put down

dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM/DD/YYYY"];

Can anyone help me correct this? Thanks

2 Answers

Patrik Alam,

I believe the error is within your date format string, @"MM/DD/YYYY". You have to be careful to put the appropriate lower case or upper case letters to represent the date pattern. In your current date pattern if you ran it through Xcode it would return, 08/228/2013, for today's date (8/16/2013).

The MM will return 08 for the month of August, which is what we want.

The DD will return the "day of the year", not the date which is 16.

And according to the link below an uppercase Y will return the year for "week of the year" calendars. I'm not sure what that means but if you ran your code through Xcode it will return 2013. I think the safer year representation for your pattern would be to use the lower case 'y' instead.

So the correct pattern for the date would look like @"MM/dd/yyyy".

http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns

I hope this helps.

Thanks so much David!

You're welcome.

...moved...