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

Navid Mirzaie Milani
Navid Mirzaie Milani
6,274 Points

Challange: Using NSDate create a date object that is 10 days from today and call it 'futureDate'.

Im getting the error : Bummer! Your date calculation seems incorrect. Are you using the product of 10 and 'secondsPerDay'?

but when i run the code below in my Xcode the code runs correctly and im getting 27-05-2014 (10 days from today).

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

NSDate *today = [[NSDate alloc]init];

NSDate *futureDate = [[NSDate alloc]init]; futureDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];

i don't know what the problem is.

4 Answers

Dave Ko
Dave Ko
11,915 Points
NSTimeInterval secondsPerDay = 60 * 60 * 24;  // <--- remove the 10 from here
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// Add your code below

NSDate *today = [[NSDate alloc]init];
NSDate *futureDate = [[NSDate alloc]init];
futureDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay * 10]; // <--- add * 10 after seconds var. 

See short comments, hope this helps.

Guillaume Maka
PLUS
Guillaume Maka
Courses Plus Student 10,224 Points

Try this:

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

NSDate *today = [NSDate date];
NSDate *futureDate = [NSDate dateWithTimeInterval:secondsPerDay * 10 sinceDate:today];

First time I use the backtick and to find it on French canadian keyboard, just mess

Navid Mirzaie Milani
Navid Mirzaie Milani
6,274 Points

Tnx Dave Ko ,

Though very strange because i test the above code you gave me also and then it gave me a error ... mm. anyway thank u it worked!

Navid Mirzaie Milani
Navid Mirzaie Milani
6,274 Points

@Guillaume Maka

aah what a coincidence i just was figuring out how i can manage to calculate the date in the past on base of the current date, thank u very much!