object-c计算指定时间与当前的时间差

头文件(.h):

#import <Foundation/Foundation.h>

@interface LuDate : NSDate
+(NSString *) compareCurrentTime:(NSString*) strDate;
@end

.m文件:

/**

 * 计算指定时间与当前的时间差

 * @param compareDate   某一指定时间

 * @return 多少(秒or分or天or月or年)+前 (比如,3天前、10分钟前)

 */

+(NSString *) compareCurrentTime:(NSString*) strDate

{

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

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

    NSDate *compareDate= [dateFormatter dateFromString:strDate];

    NSTimeInterval  timeInterval = [compareDate timeIntervalSinceNow];

    timeInterval = -timeInterval;

    long temp = ;

    NSString *result;

    if (timeInterval < ) {

        result = [NSString stringWithFormat:@"刚刚"];

    }

    else if((temp = timeInterval/) <){

        result = [NSString stringWithFormat:@"%ld分前",temp];

    }

    else if((temp = temp/) <){

        result = [NSString stringWithFormat:@"%ld小前",temp];

    }

    else if((temp = temp/) <){

        result = [NSString stringWithFormat:@"%ld天前",temp];

    }

    else if((temp = temp/) <){

        result = [NSString stringWithFormat:@"%ld月前",temp];

    }

    else{

        temp = temp/;

        result = [NSString stringWithFormat:@"%ld年前",temp];

    }

    return  result;

}
@end

iOS规范化时间格式,object-C计算指定时间与当前的时间差的更多相关文章

  1. oracle 时间格式转化以及计算

    --A表中的日期字段 create_date   例如:2017-08-05  转化为2017年8月5日   oracle 在这里的双引号会忽略 select to_char(to_date(tt.c ...

  2. python3 datetime 时间格式相减 计算间隔

    info_rent = MysqlUtils.select_yezhu_rent() info_sale = MysqlUtils.select_yezhu_sale() now_time = dat ...

  3. 如何解决前端传来的时间格式与mysql表中时间格式不匹配的查询问题

    前端传过来的时间格式为“2016-07-11 11:13:10”,而数据表中对应字段`add_time`的格式为“2016-7-11”,此时sql不能直接用 "where `add_time ...

  4. js指定日期时间加一天 ,判断指定时间是否为周末

    function dateAdd(startDate) { startDate = new Date(startDate); startDate = +startDate + ***; startDa ...

  5. spark SQL读取ORC文件从Driver启动到开始执行Task(或stage)间隔时间太长(计算Partition时间太长)且产出orc单个文件中stripe个数太多问题解决方案

    1.背景: 控制上游文件个数每天7000个,每个文件大小小于256M,50亿条+,orc格式.查看每个文件的stripe个数,500个左右,查询命令:hdfs fsck viewfs://hadoop ...

  6. 将json的时间格式转换成正常的时间格式

    /** * 对Date的扩展,将 Date 转化为指定格式的String * 月(M).日(d).12小时(h).24小时(H).分(m).秒(s).周(E).季度(q) 可以用 1-2 个占位符 * ...

  7. 时间格式的字符串在ios中的转换问题

    在移动端使用时间选择器的时候,选择了一个时间转换为时间戳,谷歌浏览器以及安卓手机使用  new Date( 选择的时间 ).getTime()  都能够拿到时间戳, 但是在ios手机上会出现出现NAN ...

  8. NSdate 时间格式

    NSdate 时间格式 NSTimeInterval 时间间隔 基本单位 秒 NSDateFormatter 时间格式器 用于日期对象的格式化或字符串解析为日期对象 日期格式如下: y  年 M  年 ...

  9. js求指定时间的周一和周日

    /*计算指定时间的的周一和周日 return=>{mondy:Date,sundy:Date} parms:{ date:指定时间,如果不指定则取当前时间 } */ function getWe ...

随机推荐

  1. 采用jmeter和泛化测试dubbo服务接口

    采用jmeter和泛化测试dubbo服务接口 http://blog.csdn.net/linuu/article/details/54313560

  2. c# Custom Controls

    http://www.cnblogs.com/light169/archive/2008/06/11/1217139.html

  3. 洛谷 P1383 高级打字机==codevs 3333 高级打字机

    P1383 高级打字机 18通过 118提交 题目提供者yeszy 标签倍增图论高级数据结构福建省历届夏令营 难度省选/NOI- 提交该题 讨论 题解 记录 最新讨论 暂时没有讨论 题目描述 早苗入手 ...

  4. nohup 程序在后台运营 避免 xshell 卡死 通过 nohup.out分析调取系统命令时的异常分析

    nohup  程序在后台运营 避免 xshell  卡死 [root@admin1 after_fc_distributed]# nohup /root/anaconda3/bin/python da ...

  5. (转)web会话管理方式

    阅读目录 1. 基于server端session的管理 2. cookie-based的管理方式 3. token-based的管理方式 4. 安全问题 5. 总结 http是无状态的,一次请求结束, ...

  6. Robot Framework 怎样写好Test Case

    1.介绍 这是一个关于如何用Robot Framework写好Test Case的高层次的指导准则 怎样实际的与系统进行交互不在此文档范围内 最重要的准则是使测试用例尽可能的让熟悉此领域的人觉得简单易 ...

  7. 修改spring boot 启动logo

    修改spring boot 启动logo 在项目添加文件banner.txt,将需要的logo写在里面 效果:

  8. YTU 2547: Repairing a Road

    2547: Repairing a Road 时间限制: 1 Sec  内存限制: 128 MB 提交: 3  解决: 2 题目描述 You live in a small town with R b ...

  9. USACO Section 1.1PROB Your Ride Is Here

    题目传送门 不能提交哦   http://www.nocow.cn/index.php/Translate:USACO/ride /* ID: jusonal1 PROG: ride LANG: C+ ...

  10. robo 3t 在 ubuntu下安装

    如果您尝试安装最新版本robomobo调用可以现在robo3t.或者你尝试在Ubuntu 16.04上安装,按照下面的步骤和你的robomongo安装 下载最新的robomongo tar文件 wge ...