代码实现:
//时间戳转标准时间 - (void)Click1:(UIButton *)btn { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];//设置你想要的格式,hh与HH的差别:分别表示12小时制,24小时制 NSString *str = [NSString stringWithFormat:@"%@", [formatter stringFromDate:[NSDate dateWithTimeIntervalSince1970:[_timeTextFiled1.text integerValue]]]]; _standardLable1.text = str; [_timeTextFiled1 resignFirstResponder]; } //标准时间转时间戳 - (void)Click2:(UIButton *)btn { NSString *timeStr = _timeTextFiled2.text; NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"YYYYMMddHHmmss"]; // 设置你想要的格式,hh与HH的差别:分别表示12小时制,24小时制 NSDate* date1 = [formatter dateFromString:timeStr]; //将字符串按formatter转成nsdate NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[date1 timeIntervalSince1970]]; _standardLable2.text = timeSp; [_timeTextFiled2 resignFirstResponder]; }