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

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

NSTimeInterval secondsPerDay = 60 * 60 * 24 *10; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; NSDate *today = [NSDate date]; NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay];

Please correct me if I am wrong!

1 Answer

Holger Liesegang
Holger Liesegang
50,595 Points

Hi Sanghmitra Banerjee ,

You might want to use an additional NSTimeInterval variable for that - just for the challenge to pass.

So the complete solution for Challenge task 2 of 4 "Using NSDate create a date object that is 10 days from today and call it 'futureDate'." e.g. could be like:

NSTimeInterval secondsPerDay = 60 * 60 * 24;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// Add your code below
NSDate *today = [NSDate date];
NSTimeInterval future = (60 * 60 * 24) * 10;
NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow:future];
Daniel Templin
Daniel Templin
5,293 Points

And what I went with, which still cut down on variables being created, was to create "futureDate" with the calculations hinging off of the "secondsPerDay". It looked a little like:

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

Slightly less clutter for the same calculations.