iOS开发计算距离现在时间

// 计算  距离现在的时间

-(NSString *)getUTCFormateDate:(NSString *)newDate

{

      //    newsDate = @"2016-01-19 09:01";

   NSDateFormatter *dateFormatter = [[NSDateFormatterallocinit];

   [dateFormattersetDateFormat:@"yyyy-MM-dd HH:mm"];

   

   NSLog(@"newsDate = %@",newDate);

   NSDate *newsDateFormatted = [dateFormatter dateFromString:newsDate];

   NSTimeZone *timeZone = [NSTimeZonetimeZoneWithName:@"UTC"];

   [dateFormattersetTimeZone:timeZone];

    

   NSDate* current_date = [[NSDateallocinit];

   NSTimeInterval time=[current_date timeIntervalSinceDate:newsDateFormatted];//间隔的秒数

   int month=((int)time)/(3600*24*30);

   int day=((int)time)/(3600*24);

   int hour=((int)time)%(3600*24)/3600;

   int minute=((int)time)%(3600*24)/60;

   NSLog(@"time=%d",(double)time);

    

   NSString *dateContent  = nil;


   if(month!=0){

         dateContent = [NSStringstringWithFormat:@"%@%i%@",@"   ",month,@"个月前"];

    }elseif(days!=0){

         dateContent = [NSStringstringWithFormat:@"%@%i%@",@"   ",days,@"天前"];

    }elseif(hours!=0){

           dateContent = [NSStringstringWithFormat:@"%@%i%@",@"   ",hours,@"小时前"];

    }elseif(minute !=0){

           dateContent = [NSStringstringWithFormat:@"%@%i%@",@"   ",minute,@"分钟前"];

        

    }else

    {

        dateContent =@"刚刚";

    }

   NSLog(@"dateContent %@",dateContent);


      return dateContent;

   }


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值