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 Build a Blog Reader iPhone App Adapting Data for Display Formatting Dates with NSDateFormatter

Date Formatting issues

Hello, I am having a problem setting a date formatting style on one of the objectives :

The question asks: 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.

Here is my code below:

NSTimeInterval secondsPerDay = 60 * 60 * 24; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // Add your code below NSDate *today = [NSDate date]; NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow: 10 *secondsPerDay]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM/DD/YYYY"];

Is the error in the format?

5 Answers

Christopher Dyer
Christopher Dyer
3,634 Points

NSTimeInterval secondsPerDay = 60 * 60 * 24; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // Add your code below NSDate *today = [[NSDate alloc] init];

NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay * 10];

[dateFormatter setDateFormat:@"MM/dd/yyyy"];

works

Thomas Smallwood
Thomas Smallwood
9,870 Points

Hi Rick,

You do have a an issue with the formatting. The 'DD' should be lowercase 'dd'. This won't create a compile error. If you are getting a compiler error that is because you declaring dateFormatter twice. Hope this helps you.

Tom

Thank you

Thomas Smallwood
Thomas Smallwood
9,870 Points

You are very welcome. Vote up the answer if it worked for you. Thanks!

Sorry Tom, still no dice--the editor is red flagging this again:

NSDate *today = [NSDate date]; NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow: 10 *secondsPerDay]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM/dd/yyyy"];

Again though, I appreciate if you can find out what's up with this.

-R

Stephen Wall
Stephen Wall
Courses Plus Student 27,294 Points

Code looks great, just worked for me. Sometimes I find I have to delete and reenter my code to get it to work on the website.