NSDateFormatter and yyyy-MM-dd

You are facing this problem because your date formatter is not correct.Suppose your newInvoice.date variable store “11:02:23″ the your dateFormatter should be @”yy:MM:dd” and if your newInvoice.date variable store”2/22/11″ then your dateFormatter should be @”MM/dd/yy”

NSDate *dateTemp = [[NSDate alloc] init];
NSDateFormatter *dateFormat1 = [[NSDateFormatter alloc] init];
NSDateFormatter *dateFormat2 = [[NSDateFormatter alloc] init];

[dateFormat1 setDateFormat:@"MM/dd/yy"];
[dateFormat2 setDateFormat:@"yyyy-MM-dd"];

dateTemp = [dateFormat1 dateFromString:newInvoice.date];
newInvoice.date = [dateFormat2 stringFromDate:dateTemp];

both format should be according to your requirement to get the correct result

Leave a Comment