iOS规范化时间格式,object-C计算指定时间与当前的时间差
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计算指定时间与当前的时间差的更多相关文章
- oracle 时间格式转化以及计算
--A表中的日期字段 create_date 例如:2017-08-05 转化为2017年8月5日 oracle 在这里的双引号会忽略 select to_char(to_date(tt.c ...
- python3 datetime 时间格式相减 计算间隔
info_rent = MysqlUtils.select_yezhu_rent() info_sale = MysqlUtils.select_yezhu_sale() now_time = dat ...
- 如何解决前端传来的时间格式与mysql表中时间格式不匹配的查询问题
前端传过来的时间格式为“2016-07-11 11:13:10”,而数据表中对应字段`add_time`的格式为“2016-7-11”,此时sql不能直接用 "where `add_time ...
- js指定日期时间加一天 ,判断指定时间是否为周末
function dateAdd(startDate) { startDate = new Date(startDate); startDate = +startDate + ***; startDa ...
- spark SQL读取ORC文件从Driver启动到开始执行Task(或stage)间隔时间太长(计算Partition时间太长)且产出orc单个文件中stripe个数太多问题解决方案
1.背景: 控制上游文件个数每天7000个,每个文件大小小于256M,50亿条+,orc格式.查看每个文件的stripe个数,500个左右,查询命令:hdfs fsck viewfs://hadoop ...
- 将json的时间格式转换成正常的时间格式
/** * 对Date的扩展,将 Date 转化为指定格式的String * 月(M).日(d).12小时(h).24小时(H).分(m).秒(s).周(E).季度(q) 可以用 1-2 个占位符 * ...
- 时间格式的字符串在ios中的转换问题
在移动端使用时间选择器的时候,选择了一个时间转换为时间戳,谷歌浏览器以及安卓手机使用 new Date( 选择的时间 ).getTime() 都能够拿到时间戳, 但是在ios手机上会出现出现NAN ...
- NSdate 时间格式
NSdate 时间格式 NSTimeInterval 时间间隔 基本单位 秒 NSDateFormatter 时间格式器 用于日期对象的格式化或字符串解析为日期对象 日期格式如下: y 年 M 年 ...
- js求指定时间的周一和周日
/*计算指定时间的的周一和周日 return=>{mondy:Date,sundy:Date} parms:{ date:指定时间,如果不指定则取当前时间 } */ function getWe ...
随机推荐
- MySQL架构优化实战系列4:SQL优化步骤与常用管理命令
- 百度语音识别API初探
近期想做个东西把大段对话转成文字.用语音输入法太慢,所以想到看有没有现成的API,网上一搜,基本就是百度和讯飞. 这里先看百度的 笔者使用的是Java版本号的 下载地址:http://bos.nj.b ...
- angularJS 系列(七)
In AngularJS 1.3+, there is One-time binding built-in: The main purpose of one-time binding expressi ...
- 在DevExpress GridControl的一列中显示图片
作者:jiankunking 出处:http://blog.csdn.net/jiankunking 近期做项目的时候用到了将GridControl中一列设置为PictureEdit类型,然后通过这一 ...
- Android之——多线程下载演示样例
转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46883927 一.概述 说到Android中的文件下载.Android API中明 ...
- protobuf入门
,step1:准备.proto文件 syntax = "proto3"; message gps_data { int64 id = 1; string terminalId = ...
- android studio 0.8.1使用和遇到问题解决
谷歌6月底公布了五大系统,而且android studio同步升级到了android studio 0.8.1.升级了的android studio确实有一些新的变化.执行速度变快,而且还能够选择开发 ...
- Gif验证码类
package com.paic.bics.common.utils.vcode; import java.awt.AlphaComposite; import java.awt.Color; imp ...
- 在linux上处理base64加密和解密
http://snailwarrior.blog.51cto.com/680306/142472/ 2.从标准输入读取文件内容,base64编码并打印到标准输出 [root@localhost tes ...
- 关于Flask的默认session
Flask的默认session利用了Werkzeug的SecureCookie,把信息做序列化(pickle)后编码(base64),放到cookie里了. 过期时间是通过cookie的过期时间实现的 ...