zoukankan      html  css  js  c++  java
  • iOS剩余时间的计算 与 显示 返回的数据是截止时间,,我们改成剩余时间

    -(NSString *)getUTCFormateDate:(NSString *)newsDate  //newsDate服务器得到的时间
    {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm"];
       
       
        NSDate *newsDateFormatted = [dateFormatter dateFromString:newsDate];
        NSTimeZone *timeZone = [NSTimeZone timeZoneWithName:@"UTC"];
        [dateFormatter setTimeZone:timeZone];
       
        NSDate* current_date = [[NSDate alloc] init];
       
        NSTimeInterval time=[newsDateFormatted timeIntervalSinceDate:current_date];//间隔的秒数
        int days=((int)time)/(3600*24);
        int hours=((int)time)%(3600*24)/3600;
        int minute=((int)time)%(3600*24)%60;
       
        NSString *dateContent;
        if(days>0){
            dateContent=[[NSString alloc] initWithFormat:@"剩余%i天%i小时%i分钟",days,hours,minute];
        }
        else if(hours>0){
            dateContent=[[NSString alloc] initWithFormat:@"剩余%i小时%i分钟",hours,minute];
        }
        else{
            dateContent=[[NSString alloc] initWithFormat:@"剩余%i分钟",minute];
        }
       
        if (time<=0) {
            dateContent=@"";
        }
        return dateContent;
    }
  • 相关阅读:
    js关闭当前页面(窗口)的几种方式总结
    Servlet 文件上传
    Servlet Cookie 处理
    Servlet Session 跟踪
    Servlet 异常处理
    Servlet 编写过滤器
    Servlet HTTP 状态码
    Servlet 服务器 HTTP 响应
    Servlet 客户端 HTTP 请求
    Servlet 表单数据
  • 原文地址:https://www.cnblogs.com/cfl911014/p/5217069.html
Copyright © 2011-2022 走看看