1

使用 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];
4

1 回答 1

2

设置时区

[format1 setTimeZone:[NSTimeZone systemTimeZone]];

OR

[format1 setTimeZone:[NSTimeZone localTimeZone]];

希望,它会帮助你。

谢谢。

于 2013-03-20T06:29:26.837 回答