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. JAVA配置--JDK环境变量配置

    环境变量是整台电脑的全局变量,(这台电脑上)任何程序都可以读取这个变量. 如果您安装好jdk,但环境变量配置让你感到有一点模糊的话,那么请您看一下这篇,希望对您有帮助 根据打开电脑的属性(R),出现 ...

  2. Java中如何获取spring中配置的properties文件内容

    有2种方式: 一. 1.通过spring配置properties文件 [java]  <bean id="propertyConfigurer"      class=&qu ...

  3. Servlet的调试

    以下内容引用自http://wiki.jikexueyuan.com/project/servlet/debugging.html: 测试/调试Servlet始终是困难的.Servlets往往涉及大量 ...

  4. Eclipse 搭建tomcat+动态项目完整版

    1. Tomcat搭建 1.新加服务器,右击控制台的server目录->new->server->选择本地tomcat 2.配置tomcat属性(如果更改失败,将tomcat下的项目 ...

  5. iOS 自己主动释放手动释放混编

    当项目为手动释放时,Build Settings中,Objective-c Automatic Reference Conting 为YES 时,想要手动管理一些文件,在CompileSources中 ...

  6. vs2013生成lib

    引擎cocos2d-x-3.1.1 一. cocos创建一个项目.随便是lua还是cpp.这里用cpp演示 二.创建完毕之后执行下项目 之后创建两个类.例如以下 TestLib.cpp文件 #incl ...

  7. [翻译角]Learn From George, Not Pinocchio(ESLPOD)

    以下转自www.eslpod.com,翻译为本人添加.其余版权均归原网站所有. ESLPOD是一个英语学习网站,我最初知道这个网站,是因为“奶爸”<把你的英语用起来>一书的推荐. ESLP ...

  8. Delphi7目录结构

    Delphi7目录结构 打开Delphi的安装目录,如C:\Program Files\Borland\Delphi7,你将会看到目录下包含了一些文件和文件夹:Source:存放的是Delpi提供的所 ...

  9. 编译android的一些坑

    1 降级gcc g++到4.4 2 参考:http://source.android.com/source/initializing.html来配置环境 3 使用jdk1.6 包括 java java ...

  10. HDU 1379:DNA Sorting

    DNA Sorting Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...