码迷,mamicode.com
首页 > 其他好文 > 详细

时间转换HH:MM:SS格式Demo

时间:2014-10-27 21:25:17      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:ios   时间转换   

     bubuko.com,布布扣                bubuko.com,布布扣

实现代码:

#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

标签:ios   时间转换   

原文地址:http://blog.csdn.net/mhtios/article/details/40512419

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!