【问题标题】:time span for facebook (ios Application)facebook的时间跨度(ios应用程序)
【发布时间】:2011-07-20 08:04:46
【问题描述】:

我想计算 twitter 和 facebook 的时间跨度。

对于推特:-2011 年 7 月 19 日星期二 11:08:46 +0000

脸书:-2011-07-18T15:25:09+0000

我想将其转换为喜欢、1 小时前、60 分钟前、2 分钟前等。

以及如何比较这些时间值以进行时间排序。

请提供任何示例代码或任何类参考链接,以便我可以做到。

【问题讨论】:

    标签: iphone objective-c facebook ios4 iphone-sdk-3.0


    【解决方案1】:
    -(NSString *)dateDiff:(NSString *)origDate {
        NSDateFormatter *df = [[NSDateFormatter alloc] init];
        [df setFormatterBehavior:NSDateFormatterBehavior10_4];
        [df setDateFormat:@"EEE, dd MMM yy HH:mm:ss VVVV"];
        NSDate *convertedDate = [df dateFromString:origDate];
        [df release];
        NSDate *todayDate = [NSDate date];
        double ti = [convertedDate timeIntervalSinceDate:todayDate];
        ti = ti * -1;
        if(ti < 1) {
            return @"never";
        } else      if (ti < 60) {
            return @"less than a minute ago";
        } else if (ti < 3600) {
            int diff = round(ti / 60);
            return [NSString stringWithFormat:@"%d minutes ago", diff];
        } else if (ti < 86400) {
            int diff = round(ti / 60 / 60);
            return[NSString stringWithFormat:@"%d hours ago", diff];
        } else if (ti < 2629743) {
            int diff = round(ti / 60 / 60 / 24);
            return[NSString stringWithFormat:@"%d days ago", diff];
        } else {
            return @"never";
        }   
    }
    

    【讨论】:

    • 几秒钟后,我将其更改为返回 [NSString stringWithFormat:@"%d seconds ago", (int) ti];但除此之外似乎还可以。
    猜你喜欢
    • 1970-01-01
    • 2012-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-07
    • 1970-01-01
    • 1970-01-01
    • 2018-02-19
    相关资源
    最近更新 更多