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. codevs——6221 数的统计

    6221 数的统计  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 白银 Silver 题解       题目描述 Description 有一个人名字叫A,B总喜欢打他. 这 ...

  2. JDBC的异常

    以下内容引用自http://wiki.jikexueyuan.com/project/jdbc/exceptions.html: 异常处理可以允许处理一个异常情况,例如可控方式的程序定义错误. 当异常 ...

  3. elk实时日志分析平台部署搭建详细实现过程

    原文:http://blog.csdn.net/mchdba/article/details/52132663 1.ELK平台介绍 在搜索ELK资料的时候,发现这篇文章比较好,于是摘抄一小段:以下内容 ...

  4. 017 SSH

    Router>en Router#config t Enter configuration commands, one per line.  End with CNTL/Z. Router(co ...

  5. C#之快速排序 C#之插入排序 C#之选择排序 C#之冒泡排序

    C#之快速排序   算法描述 1.假定数组首位元素为“枢轴”,设定数列首位(begin)与末位(end)索引: 2.由末位索引对应元素与“枢轴”进行比较,如果末位索引对应元素大于“枢轴”元素,对末位索 ...

  6. 背包系统学习笔(tu)记(cao)

    这几天在学习背包系统,网上有看到一个挺牛逼的背包系统,不过人家那个功能很全面,一个背包系统就囊括了装备,锻造,购买等等功能(这里给出网址:https://blog.csdn.net/say__yes/ ...

  7. TensorFlow的安装与CNN测试

    0.说明 在Google开源该框架之后便使用真实K40m卡测试,由于生产环境是CentOS6.6的操作系统,但是该框架需要在Python2.7环境下执行,CentOS6.6下折腾了一天没搞定,后来换成 ...

  8. tesnorflow Batch Normalization

    1.train或者从checkpoint restore后发现moving_mean和moving_variance都是0和1 bn1_mean = graph.get_tensor_by_name( ...

  9. 第一个GraphX程序

    程序功能:收集顶点指向的邻居中所在地 /* * 找出每一个顶点所指向的邻居中所在的地区 */ import org.apache.spark.SparkContext import org.apach ...

  10. Oracle学习(四):组函数

    1.知识点:能够对比以下的录屏进行阅读 SQL> --组函数类型:avg,count,max.min,sum SQL> --工资总额 SQL> select sum(sal) fro ...