时间格式时间戳转换

                     

源代码下载

实现代码:

  1. #pragma mark - timeClick  
  2. - (void)timeClick:(UIButton *)btn  
  3. {  
  4.     long testTime = [ _timeTextFiled.text intValue];//定义一个长整形变量  
  5.     NSNumber *nsTime = [NSNumber numberWithLong:testTime];//将基本数据类型转换为NSNumber数据类型  
  6.     int hour = [nsTime intValue] / 3600;  
  7.     int minute = ([nsTime intValue] % 3600) / 60;  
  8.     int second = [nsTime intValue] % 60;  
  9.     if (hour < 10){  
  10.         if (minute < 10 && second >= 10){  
  11.             _timeLable.text = [NSString stringWithFormat:@"0%d:0%d:%d", hour, minute, second];  
  12.         }else if (minute < 10 && second < 10){  
  13.             _timeLable.text = [NSString stringWithFormat:@"0%d:0%d:0%d", hour, minute, second];  
  14.         }else if (minute >= 10 && second < 10) {  
  15.             _timeLable.text = [NSString stringWithFormat:@"0%d:%d:0%d", hour, minute, second];  
  16.         }else if (minute >= 10 && second >= 10){  
  17.             _timeLable.text = [NSString stringWithFormat:@"0%d:%d:%d", hour, minute, second];  
  18.         }  
  19.     }else {  
  20.         if (minute < 10 && second >= 10){  
  21.             _timeLable.text = [NSString stringWithFormat:@"%d:0%d:%d", hour, minute, second];  
  22.         }else if (minute < 10 && second < 10){  
  23.             _timeLable.text = [NSString stringWithFormat:@"%d:0%d:0%d", hour, minute, second];  
  24.         }else if (minute >= 10 && second < 10) {  
  25.             _timeLable.text = [NSString stringWithFormat:@"%d:%d:0%d", hour, minute, second];  
  26.         }else if (minute >= 10 && second >= 10){  
  27.             _timeLable.text = [NSString stringWithFormat:@"%d:%d:%d", hour, minute, second];  
  28.         }  
  29.     }  
  30.     //隐藏键盘  
  31.     [_timeTextFiled resignFirstResponder];  
  32. }  
原文地址:https://www.cnblogs.com/bhlsheji/p/5325499.html