I think I am using the NSDateFormatter in a wrong way. I have a UIDatePicker. When I select a date, my day label ,month label, year label and time label is set.
When I click on a save button I build up a date with this labels and send it to my server.
I do it like this.
NSString *dateStringBegin = [NSString stringWithFormat:@"%@ %@ %@ %@",lblBeginDay.text,lblBeginMonth.text,lblBeginYear.text,lblBeginTime.text];
//LOG dateStringBegin = 7 februari 2013 11:21
But my server only accepts a string that looks like this 2013-02-07 11:21
Now I am doing this in code.
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"d MMMM YYYY hh:mm"];
NSDate* date = [dateFormat dateFromString:dateStringBegin];
NSDateFormatter *dateFormat2 = [[NSDateFormatter alloc] init];
[dateFormat2 setDateFormat:@"YYYY-MM-dd HH:mm"];
NSString *dateStringBegin2 = [dateFormat2 stringFromDate:date];
Now when I look at how my dateStringBegin2 looks like, I see this.
//LOG dateStringBegin2 = 2013-12-28 11:21
Check this code:-
Hope it helps you..