北京时间属于东八区,因此我们只需要根据timeZoneForSecondsFromGMT方法进行设置即可
NSDateFormatter*formatter = [[NSDateFormatter alloc]init];
NSTimeZone* timeZone = [NSTimeZone timeZoneForSecondsFromGMT:8*60*60];
[formatter setTimeZone:timeZone];
[formatter setDateFormat:@"YYYY-MM-dd hh:MM:SS"];
NSDate*datenow = [NSDate date];
NSString* beijingtimeStr = [formatter stringFromDate:datenow];
网友评论