Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Blog Reader iPhone App Adapting Data for Display Formatting Dates with NSDateFormatter

Navid Mirzaie Milani
Navid Mirzaie Milani
6,273 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,273 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,273 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!