首页 > 代码库 > 时间转换HH:MM:SS格式Demo
时间转换HH:MM:SS格式Demo
实现代码:
#pragma mark - timeClick - (void)timeClick:(UIButton *)btn { long testTime = [ _timeTextFiled.text intValue];//定义一个长整形变量 NSNumber *nsTime = [NSNumber numberWithLong:testTime];//将基本数据类型转换为NSNumber数据类型 int hour = [nsTime intValue] / 3600; int minute = ([nsTime intValue] % 3600) / 60; int second = [nsTime intValue] % 60; if (hour < 10){ if (minute < 10 && second >= 10){ _timeLable.text = [NSString stringWithFormat:@"0%d:0%d:%d", hour, minute, second]; }else if (minute < 10 && second < 10){ _timeLable.text = [NSString stringWithFormat:@"0%d:0%d:0%d", hour, minute, second]; }else if (minute >= 10 && second < 10) { _timeLable.text = [NSString stringWithFormat:@"0%d:%d:0%d", hour, minute, second]; }else if (minute >= 10 && second >= 10){ _timeLable.text = [NSString stringWithFormat:@"0%d:%d:%d", hour, minute, second]; } }else { if (minute < 10 && second >= 10){ _timeLable.text = [NSString stringWithFormat:@"%d:0%d:%d", hour, minute, second]; }else if (minute < 10 && second < 10){ _timeLable.text = [NSString stringWithFormat:@"%d:0%d:0%d", hour, minute, second]; }else if (minute >= 10 && second < 10) { _timeLable.text = [NSString stringWithFormat:@"%d:%d:0%d", hour, minute, second]; }else if (minute >= 10 && second >= 10){ _timeLable.text = [NSString stringWithFormat:@"%d:%d:%d", hour, minute, second]; } } //隐藏键盘 [_timeTextFiled resignFirstResponder]; }
时间转换HH:MM:SS格式Demo
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。