使用 NSDateFormatter 来改变日期的格式,它只是返回前一天给它的日期。这是代码:
NSString *strDate = [self.mArrEventDate objectAtIndex:i];
NSString *str = [[NSString alloc] init];
str = [strDate stringByReplacingOccurrencesOfString:@"/" withString:@"-"];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// ...using a date format corresponding to your date
[dateFormatter setDateFormat:@"dd/MM/yyyy"];
// Parse the string representation of the date
NSDate *date = [dateFormatter dateFromString:strDate];
NSDateFormatter *format1 = [[NSDateFormatter alloc]init];
[format1 setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
[format1 setDateFormat:@"yyyy-MM-dd"];
NSString *sDate = [format1 stringFromDate:date];