zoukankan      html  css  js  c++  java
  • 计算某一天距离今天多少天,多少小时,多少分钟

    - (NSString *)intervalSinceNow: (NSString *) theDate
    {
        NSString *timeString=@"";
     
        NSDateFormatter *format=[[NSDateFormatter alloc] init];
        [format setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSDate *fromdate=[format dateFromString:theDate];
        NSTimeZone *fromzone = [NSTimeZone systemTimeZone];
        NSInteger frominterval = [fromzone secondsFromGMTForDate: fromdate];
        NSDate *fromDate = [fromdate  dateByAddingTimeInterval: frominterval];
     
        //获取当前时间
        NSDate *adate = [NSDate date];
        NSTimeZone *zone = [NSTimeZone systemTimeZone];
        NSInteger interval = [zone secondsFromGMTForDate: adate];
        NSDate *localeDate = [adate  dateByAddingTimeInterval: interval];
         
        double intervalTime = [fromDate timeIntervalSinceReferenceDate] - [localeDate timeIntervalSinceReferenceDate];
        long lTime = fabs((long)intervalTime);
        NSInteger iSeconds =  lTime % 60;
        NSInteger iMinutes = (lTime / 60) % 60;
        NSInteger iHours = fabs(lTime/3600);
        NSInteger iDays = lTime/60/60/24;
        NSInteger iMonth =lTime/60/60/24/12;
        NSInteger iYears = lTime/60/60/24/384;
         
         
        NSLog(@"相差%d年%d月 或者 %d日%d时%d分%d秒", iYears,iMonth,iDays,iHours,iMinutes,iSeconds);
         
         
        if (iHours<1 && iMinutes>0)
        {
            timeString=[NSString stringWithFormat:@"%d分",iMinutes];
             
        }else if (iHours>0&&iDays<1 && iMinutes>0) {
            timeString=[NSString stringWithFormat:@"%d时%d分",iHours,iMinutes];
        }
        else if (iHours>0&&iDays<1) {
            timeString=[NSString stringWithFormat:@"%d时",iHours];
        }else if (iDays>0 && iHours>0)
        {
            timeString=[NSString stringWithFormat:@"%d天%d时",iDays,iHours];
        }
       else if (iDays>0)
        {
            timeString=[NSString stringWithFormat:@"%d天",iDays];
        }
        return timeString;
    }
  • 相关阅读:
    cubestore driver 添加auth认证
    cubestore 添加auth 认证
    基于s3 扩展cubestore
    cube.js 预聚合检查
    cube.js 集成cubestore 时间格式问题的一些说明
    cube.js 集成cubestore 时间格式问题
    Building a GraphQL to SQL Compiler on Postgres, MS SQL and MySQL
    支持minio cubestore docker 镜像
    数据治理怎么做
    使用project制定项目计划可以分为六个步骤
  • 原文地址:https://www.cnblogs.com/joesen/p/3540102.html
Copyright © 2011-2022 走看看