实例说明如何把gtm+0转化成gtm+8


NSString *stringdata=[NSString stringWithFormat:@"2012-09-28 08:36:29"];


NSDateFormatter *datefor=[[NSDateFormatter alloc]init];


[datefor setDateFormat:@"YYYY-MM-dd HH:mm:ss"];


NSDate *olddate=[datefor dateFromString:stringdata];


NSTimeInterval timezone=[[NSTimeZone systemTimeZone]secondsFromGMT];


NSDate *newdate=[olddate dateByAddingTimeInterval:timezone];




NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];


[dateformatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];


NSString * locationString=[dateformatter stringFromDate:newdate];


NSLog(@"oldstring==%@",stringdata);


NSLog(@"newstring==%@",locationString);

你可能感兴趣的:(实例说明如何把gtm+0转化成gtm+8)