美文网首页
返回天时分秒

返回天时分秒

作者: 阿兹尔 | 来源:发表于2018-06-21 11:51 被阅读8次

    /// 传入 秒

    • (NSString *) secondsToTime:(int)nStopTime{
      NSString *sb;
      int ms1 = nStopTime;

      int mm = 60;

      int hh = 60*60;

      int dd = 246060;

      if (ms1 < mm) {
      sb = [NSString stringWithFormat:@"%d秒",ms1];
      }else if (ms1 == mm ) {
      sb = @"1分";
      } else if (ms1>mm && ms1 <hh) {
      int minutes = ms1/mm;
      int seconds = ms1%mm;
      sb = [NSString stringWithFormat:@"%d分%d秒",minutes,seconds];
      }else if (ms1 == hh ) {
      sb = @"1小时";
      } else if ( hh < ms1 && ms1 < dd ) {
      int hours = ms1/hh;
      int temp = ms1 - hours*hh;
      int minutes = temp/mm;
      int seconds = temp%mm;
      sb = [NSString stringWithFormat:@"%d小时%d分%d秒",hours,minutes,seconds];
      }else if (ms1 == dd ) {
      sb = @"1天";
      }else {
      int day = ms1/dd;
      int temp = ms1 - day dd;
      if (temp < mm) {
      sb = [NSString stringWithFormat:@"%d天%d秒",day,temp];
      }else if (temp == mm ) {
      sb = [NSString stringWithFormat:@"%d天1分",day];
      }else if (temp>mm && temp <hh) {
      int minutes = ms1/mm;
      int seconds = ms1%mm;
      sb = [NSString stringWithFormat:@"%d天%d分%d秒",day,minutes,seconds];
      }else if (temp == hh ) {
      sb = [NSString stringWithFormat:@"%d天1小时",day];
      }else if ( hh < temp && temp < dd ) {
      int hours = ms1/hh;
      int temps = ms1 - hours
      hh;
      int minutes = temps/mm;
      int seconds = temps%mm;
      sb = [NSString stringWithFormat:@"%d天%d小时%d分%d秒",day,hours,minutes,seconds];
      }
      }
      return sb;
      }

    相关文章

      网友评论

          本文标题:返回天时分秒

          本文链接:https://www.haomeiwen.com/subject/vreqyftx.html