时间格式的转化

当输出时间的格式为

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];

    }

原文地址:https://www.cnblogs.com/wangzhen-Me/p/4845151.html