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 ...
随机推荐
- HTML5 全屏化操作功能
由于项目中用到了全屏化挫折功能,查看了API后写了一个简单的全屏化model <!DOCTYPE html> <html> <head> <meta http ...
- Linux系统备份还原工具4(rsync/远程数据同步工具)
rsync即是能备份系统也是数据同步的工具. 在Jenkins上可以使用rsync结合SSH的免密登录做数据同步和分发.这样一来可以达到部署全命令化,不需要依赖任何插件去实现. 命令参考:http:/ ...
- rsyslog trouble shooting
openstack,swift的log不输出了.trouble shooting过程 , 发现我们的程序 /var/log/swift/proxy.log等总是不输出log. 因为log rsyslo ...
- Mysql的timestamp类型,自动记录数据的更新时间
datetime也可以设置自动更新的
- ArcGIS for Android入门程序之DrawTool2.0
来自:http://blog.csdn.net/arcgis_mobile/article/details/8084763 GISpace博客<ArcGIS for Android入门程序之Dr ...
- 【C++ STL应用与实现】18: 怎样使用迭代器适配器
本系列文章的文件夹在这里:文件夹. 通过文件夹里能够对STL整体有个大概了解 前言 本文介绍了STL中的迭代器适配器(iterator adapter)的概念及其用法演示样例.迭代器适配器能够和标准库 ...
- 在不同的系统中的virtualbox中安装Ubuntu SDK
对非常多的开发人员来说.你们可能使用的不是Ubuntu操作系统.在这样的情况下,开发人员须要在自己的操作系统中(OS X及Windows)安装virtualbox,并在VirtualBox中安装Ubu ...
- 如何让aboboo 便携版在citrix下使用(aboboo在IPAD上使用)aboboo苹果版
公司使用的是citrix的共享虚拟桌面.如何可以让aboboo在其下面运行呢? 网上有提供绿色版,但是总是弹出首次配置无法安装的报错界面. 察看帮助文档:http://www.aboboo.com/d ...
- Codesys——AD_DA在PID控制中的作用
1. 摘要 PID控制中用到AD/DA的输入/输出,给出其大致实现思路. 2. 思路 3. 总结 无
- 使用SwingWork反而阻塞SwingUI
最近加载图片的过程中使用了SwingWork来下载图片,但是发现会使得Swing的UI界面假死 查看了一下资料,SwingWork的设计初衷就是为了解决卡死UI的问题,正常使用应该没有问题,但是有一点 ...