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 trialCarlos Lagares
4,332 PointsDates
"Object with the date of ten days from now": It is working for me on xcode, but it is not under treehouse environment, could you help me?
6 Answers
Parker Skiba
5,583 PointsPost your code so we can see what is going on.
Carlos Lagares
4,332 PointsAlready solved, was repeating a variable in your compiler, but sometimes as we dont get any info about errors, it is difficult to understand what we are doing wrong ;)
Parker Skiba
5,583 PointsCool
Carlos Lagares
4,332 PointsLast question...
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init]; [dateFormatter1 setDateFormat:@"MM/dd/yyyy"];
Is not that the format for month/day/year?
Parker Skiba
5,583 PointsIf that is the format which you are parsing from... Are you getting your date from the JSON data off the team treehouse blog reader page? because if so the format which in which you pass the string through is going to be
[dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
Then you create a NSDate from your String property which is parsed from JSON and then you can make your NSDateFormatter
[dateFormatter setDateFormat:@"MM-dd-yyyy"];
and have it return the NSDate with dateFormatter using stringFromDate.
Parker Skiba
5,583 PointsOverall I would write something like this
- (NSString *) formattedDate {
NSDateFormatter *dateFormatter1 = [[NSDateFormatter alloc] init];
[dateFormatter1 setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate *date = [dateFormatter1 dateFromString:self.date];
[dateFormatter1 setDateFormat:@"MM dd yyyy"];
return [dateFormatter1 stringFromDate:date];
}
You can find the date formats in the documentation, If you cant find it there its also here I believe http://waracle.net/iphone-nsdateformatter-date-formatting-table/