码迷,mamicode.com
首页 > 其他好文 > 详细

时间格式的转化

时间:2015-09-28 23:39:53      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

当输出时间的格式为

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

    }

时间格式的转化

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!