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
Husnain Javed
1,570 PointsHelp 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
Jerome Garot
2,886 PointsWhat'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
Husnain Javed
1,570 PointsHusnain Javed
1,570 PointsCan I have the code please? Because I tried all the code lines but it isn't accepting them.
Jerome Garot
2,886 PointsJerome Garot
2,886 PointsWhy don't you post the thing you think it should be and we can break it down so you learn something from it ;)
Husnain Javed
1,570 PointsHusnain Javed
1,570 PointsThis 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
Husnain Javed
1,570 PointsHusnain Javed
1,570 PointsThank you very much for your time dedicated to my problem, but I resolved it by replacing DD with dd.
Fix:
DD --> dd
Jerome Garot
2,886 PointsJerome Garot
2,886 PointsExactly what I was gonna post.
I also used small y's myself:
I also just used secondsPerDay * 10 for the 10 days thing.