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. SpringBoot学习day01

    SpringBoot目的在于创建和启动新的基于Spring框架的项目.SpringBoot会选择最合适的Spring子项目和第三方开源库进行整合.大部分SpringBoot应用只需要非常少量的配置就可 ...

  2. Hive之Order,Sort,Cluster and Distribute By

    测试数据 create table sort_test( id int, name string ) row format delimited fields terminated by '\t' li ...

  3. 我的arcgis培训照片12

    来自:http://www.cioiot.com/successview-381-1.html

  4. java监控工具jconsole

    jconsole可以监控本地和远程进程 jvisualvm

  5. Linux系统下ssh登陆很慢的解决办法

    很多的Linux用户发现连接上Linux服务器在输入用户名之后还要再等一下才能输入密码,时间过长了,现在小白与大家分享一下如何解决ssh登陆问题的问题,希望对您有所帮助. 1.我们平时登陆Linux服 ...

  6. [计算机故障]笔记本无法启动,开机启动出现“Operating System Not Found”无法进系统

    背景介绍:同事的一台索尼的笔记本,安装XP.开机启动出现“Operating System Not Found”无法进系统 诊断: 初步判断硬盘故障.但听声音,没有异响. 开机按F2进入BIOS设置. ...

  7. 【bzoj3288】Mato矩阵

    题目大意:给定一个n阶行列式,第i行第j列为GCD(i,j),求这个行列式的值 高斯消元之后发现对角线上的东西是phi 于是线性筛出所有的欧拉函数即可 #include<algorithm> ...

  8. linux下库的使用

    1 指定使用了什么库 -lstdc++ 这样链接的时候就会去指定的目录下找链接库,优先使用动态库.然后在elf文件中加入依赖关系,放在NEEDED中. 2 指定在哪里去找库 -Wl,-rpath,so ...

  9. pagefile.sys

    pagefile.sys

  10. go 安装方法

    wget https://storage.googleapis.com/golang/go1.5.linux-amd64.tar.gz sudo tar -C /usr/local -xzf go1. ...