zoukankan      html  css  js  c++  java
  • 计算时间差

    - (NSString *)intervalSinceNow: (NSString *) theDate

    {

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

        [date setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

        NSDate * oldDate=[date dateFromString:theDate];

        NSTimeInterval temp1=[oldDate timeIntervalSince1970]*1;

        NSDate* nowDate = [NSDate dateWithTimeIntervalSinceNow:0];

        NSTimeInterval temp12=[nowDate timeIntervalSince1970];

        NSString *timeString=@"";

        NSTimeInterval cha=temp2-temp1;

        if (cha/3600<1) {

            timeString = [NSString stringWithFormat:@"%f", cha/60];

            timeString = [timeString substringToIndex:timeString.length-7];

            timeString=[NSString stringWithFormat:@"%@分钟前", timeString];

        }

        if (cha/3600>1&&cha/86400<1) {

            timeString = [NSString stringWithFormat:@"%f", cha/3600];

            timeString = [timeString substringToIndex:timeString.length-7];

            timeString=[NSString stringWithFormat:@"%@小时前", timeString];

        }

        if (cha/86400>1)

        {

            timeString = [NSString stringWithFormat:@"%f", cha/86400];

            timeString = [timeString substringToIndex:timeString.length-7];

            timeString=[NSString stringWithFormat:@"%@天前", timeString];

        }

        return timeString;

    }

  • 相关阅读:
    3.2.8.1 打印与否
    3.2.8 sed 的运作
    3.2.7.1 替换细节
    3.2.7 基本用法
    3.2.6 在文本文件里进行替换
    3.2.5 程序与正则表达式
    pgm2
    pgm6
    pgm7
    pgm8
  • 原文地址:https://www.cnblogs.com/changeUniversal/p/4729492.html
Copyright © 2011-2022 走看看