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 trialRick Wolchuk
2,063 PointsDate Formatting issues
Hello, I am having a problem setting a date formatting style on one of the objectives :
The question asks: 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.
Here is my code below:
NSTimeInterval secondsPerDay = 60 * 60 * 24; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // Add your code below NSDate *today = [NSDate date]; NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow: 10 *secondsPerDay]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM/DD/YYYY"];
Is the error in the format?
5 Answers
Thomas Smallwood
9,870 PointsHere is the site that shows the unicode date format patterns...
http://www.unicode.org/reports/tr35/tr35-25.html#Date_Format_Patterns
Christopher Dyer
3,634 PointsNSTimeInterval secondsPerDay = 60 * 60 * 24; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; // Add your code below NSDate *today = [[NSDate alloc] init];
NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow:secondsPerDay * 10];
[dateFormatter setDateFormat:@"MM/dd/yyyy"];
works
Thomas Smallwood
9,870 PointsHi Rick,
You do have a an issue with the formatting. The 'DD' should be lowercase 'dd'. This won't create a compile error. If you are getting a compiler error that is because you declaring dateFormatter twice. Hope this helps you.
Tom
Rick Wolchuk
2,063 PointsThank you
Thomas Smallwood
9,870 PointsYou are very welcome. Vote up the answer if it worked for you. Thanks!
Rick Wolchuk
2,063 PointsSorry Tom, still no dice--the editor is red flagging this again:
NSDate *today = [NSDate date]; NSDate *futureDate = [NSDate dateWithTimeIntervalSinceNow: 10 *secondsPerDay]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"MM/dd/yyyy"];
Again though, I appreciate if you can find out what's up with this.
-R
Stephen Wall
Courses Plus Student 27,294 PointsCode looks great, just worked for me. Sometimes I find I have to delete and reenter my code to get it to work on the website.