Update: I was able to get the date converted from the server json to 2012/09/05 10:45
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
for (NSString *slotKey in myslots.allKeys) {
NSDictionary *slot = [myslots valueForKey:slotKey];
for (myDays in slot){
if ([[self.myDays objectForKey:@"isReservable"] isEqualToNumber:[NSNumber numberWithInt:1]]){
NSDate *newDate = [df dateFromString:[self.myDays objectForKey:@"begin"]];
if (newDate){
[self.timesArray addObject:newDate];
}
NSLog(@"these are the returned newdates: %@",newDate);
NSLog(@"This is the timesArray: %@", self.timesArray);
}
}
}
My NSLog of These are still returning null and my This is the timesArray is ()
I am not understanding what is wrong. Thanks for the help.
Are you sure that your inputs are valid?
Also, your first log only says that the date formatter got allocated–not that it will produce results for your inputs.
Ran a quick test, it looks like your problem is in the timezone portion of the date. The following code will return:
date is 2012-10-04 16:15:00 +0000You can check explicitly to see if the date formatter can get a date from your string like this:
Since the date string is coming from server-side I would suggest investigating how it’s sending down timezones and change them manually on your end. Not pretty but regexs are your friend.