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

Help with date formatting in iOS

Please help me, i don't have any idea how to do this code challenge.

Question:

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.

1 Answer

What's the problem? (Try and explain what you're problem is, otherwise no one can help you.)

The problem I was having on that one was that I was trying to set up the formatter again, but it was already initialized on the 2nd line.

Jerome

Can I have the code please? Because I tried all the code lines but it isn't accepting them.

Why don't you post the thing you think it should be and we can break it down so you learn something from it ;)

This is my code:

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

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

[dateFormatter setDateFormat:@"MM/DD/YYYY"];

// Thanks

Thank you very much for your time dedicated to my problem, but I resolved it by replacing DD with dd.

Fix:

DD --> dd

Exactly what I was gonna post.

I also used small y's myself:

I also just used secondsPerDay * 10 for the 10 days thing.