zoukankan      html  css  js  c++  java
  • 时间格式的转化

    当输出时间的格式为

    Mon Sep 28 22:25:56 +0800 2015    如果要显示%@秒/分/时以前时需要对其进行进行格式编写

    NSDateFormatter * formart=[[NSDateFormatter alloc]init];

    //此句话是为了模拟器上输出正常,而在真机上的时候输出为空

        NSLocale * local=[[NSLocale alloc]initWithLocaleIdentifier:@"en_US"];

        [formart setLocale:local];

        [formart setDateFormat:@"EEE MMM d HH:mm:ss zzz yyyy"];

        NSDate * date=[formart dateFromString:li.Time];

        double inter=fabs([date timeIntervalSinceNow]);

        if (inter < 60)

        {

            cell.Timelable.text=[NSString stringWithFormat:@"%.0lf秒以前",inter];

        }

        else if(inter >60 && inter <60*60)

        {

            cell.Timelable.text=[NSString stringWithFormat:@"%.0lf分钟以前",inter/60];

        }

        else if(inter >60*60 && inter <60*60*24)

        {

            cell.Timelable.text=[NSString stringWithFormat:@"今天 %@",date];

        }

        else

        {

            double i= inter/(24*60*60);

            cell.Timelable.text=[NSString stringWithFormat:@"%.0lf天以前",i];

        }

  • 相关阅读:
    谷哥的小弟学后台(29)——动态代理
    HDU
    jni 入门 android的C编程之旅 --->环境搭建&&helloworld
    C# 开发系列(二)
    C# 开发系列(一)
    ajax跨域实现api 接口调用
    dependency injection(2)
    要读的书单
    dependency injection
    php dependency innjection
  • 原文地址:https://www.cnblogs.com/wangzhen-Me/p/4845151.html
Copyright © 2011-2022 走看看