时间格式时间戳转换
实现代码:
- #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];
- }