解決方案:
使用如下代碼:
NSDate *date=[_pickerVIew date]; NSDateFormatter *formatter=[[NSDateFormatter alloc]init]; formatter.dateFormat=@"yy-MM-dd HH:mm:ss"; NSString *timeStr=[formatter stringFromDate:date]; NSLog(@"date-----%@",date); NSLog(@"timeStr-------%@",timeStr); NSTimeZone *timeZone=[NSTimeZone systemTimeZone]; NSInteger seconds=[timeZone secondsFromGMTForDate:date]; NSDate *newDate=[date dateByAddingTimeInterval:seconds]; NSString *newTimeStr=[formatter stringFromDate:newDate]; NSLog(@"newDate----%@",newDate); NSLog(@"newTimeStr-------%@",newTimeStr);
代碼打印結果: