zoukankan      html  css  js  c++  java
  • ios开发之--把秒转换为天时分秒

    把秒转换成时分秒:

    - (NSString *)timeFormatted:(int)totalSeconds
    {
    
        int seconds = totalSeconds % 60;
        int minutes = (totalSeconds / 60) % 60;
        int hours = totalSeconds / 3600;
    
        return [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds];
    } 

    把毫秒转换成时间格式:

        //将时间数据(毫秒)转换为天和小时  
        - (NSString*)getOvertime:(NSString*)mStr  
        {  
            long msec = [mStr longLongValue];  
              
            if (msec <= 0)  
            {  
                return @"";  
            }  
              
            NSInteger d = msec/1000/60/60/24;  
            NSInteger h = msec/1000/60/60%24;  
            //NSInteger  m = msec/1000/60%60;  
            //NSInteger  s = msec/1000%60;  
              
            NSString *_tStr = @"";  
            NSString *_dStr = @"";  
            NSString *_hStr = @"";  
            NSString *_hTimeType = @"defaultColor";  
              
            if (d > 0)  
            {  
                _dStr = [NSString stringWithFormat:@"%ld天",d];  
            }  
              
            if (h > 0)  
            {  
                _hStr = [NSString stringWithFormat:@"%ld小时",h];  
            }  
              
            //小于2小时 高亮显示  
            if (h > 0 && h < 2)  
            {  
                _hTimeType = @"hightColor";  
            }  
              
            _tStr = [NSString stringWithFormat:@"%@%@后到期-%@",_dStr,_hStr,_hTimeType];  
              
            return _tStr;  
        }  
  • 相关阅读:
    day 06小结
    day 05小结
    day 05作业
    day 04作业
    day 03作业
    今日小结
    day 02小结
    hdu 4608 I-number(13多校#1 ,1009)
    zoj 2316 Matrix Multiplication(D)
    zoj 2316 Matrix Multiplication(2-D)
  • 原文地址:https://www.cnblogs.com/hero11223/p/7844585.html
Copyright © 2011-2022 走看看