iOS 计算时间差
/**
* 计算指定时间与当前的时间差
* @param compareDate 某一指定时间
* @return 多少(秒or分or天or月or年)+前 (比如,3天前、10分钟前)
*/
+(NSString *) compareCurrentTime:(NSDate*) compareDate
//
{
NSTimeInterval timeInterval = [compareDate timeIntervalSinceNow];
timeInterval = -timeInterval;
long temp = ;
NSString *result;
if (timeInterval < ) {
result = [NSStringstringWithFormat:@"刚刚"];
}
else if((temp = timeInterval/) <){
result = [NSStringstringWithFormat:@"%d分前",temp];
} else if((temp = temp/) <){
result = [NSStringstringWithFormat:@"%d小前",temp];
} else if((temp = temp/) <){
result = [NSStringstringWithFormat:@"%d天前",temp];
} else if((temp = temp/) <){
result = [NSStringstringWithFormat:@"%d月前",temp];
}
else{
temp = temp/;
result = [NSStringstringWithFormat:@"%d年前",temp];
} return result;
}
iOS 计算时间差的更多相关文章
- IOS 计算两个经纬度之间的距离
IOS 计算两个经纬度之间的距离 一 丶 -(double)distanceBetweenOrderBy:(double) lat1 :(double) lat2 :(double) lng1 :(d ...
- Android计算时间差
想要写个根据消耗时长来确定开始结束时间的小工具,发现Android处理时间上有点累,可能是我没找到合适的方法吧,先把我的解决办法贴出来,有好的解决方法还希望提醒一下: 1.根据时间字符串获取毫秒数 p ...
- 【转载】c/c++在windows下获取时间和计算时间差的几种方法总结
一.标准C和C++都可用 1.获取时间用time_t time( time_t * timer ),计算时间差使用double difftime( time_t timer1, time_t time ...
- C#计算时间差值
/// <summary> /// 计算时间差值 /// </summary> /// <param name="DateTime1">< ...
- 登录超时自动退出,计算时间差-b
// 此方法适用于所有被创建过的controller,且当前controller生命周期存在,如有错误的地方望大神斧正 // 说一下我们的需求和实现原理,需求:在点击home键退出但没有滑飞它,5分 ...
- python分页和session和计算时间差
分页 #!/usr/bin/env python # -*- coding:utf-8 -*- class Pagenation: def __init__(self,current_page,all ...
- js计算时间差,包括计算,天,时,分,秒
收集两个计算时间差的计算方法代码片段: var date1=new Date(); //开始时间 var date2=new Date(); //结束时间 var date3=date2.getTim ...
- Android中计算时间差的实现方法
今天为“至简天气”增加了一项功能:在启动时根据上次更新数据的时间判断是否有必要更新数据,因为 weather.com.cn 的实况数据貌似是25分钟才会刷新一次,只有在据上次更新的时间达25分钟以上才 ...
- datetime 计算时间差
计算时间差: .date() # 格式化 .timedelta() # 时间差 import datetime # 今天 today = datetime.datetime ...
随机推荐
- MVC3 模板页页预留Section
一.模板页 Razor出现后我们就可以选择不再使用asp.net master 模板页.取而代之的是cshtml razor的模板文件.用法个人认为还是和master模板页类似.但在mater模板页的 ...
- unity, Destroy注意事项
Destroy不是立即发生作用,而是推迟到帧末,所以下面代码是错误的: void OnTriggerEnter(Collider other){ if (other.gameObject.tag ...
- JUC组件扩展(二)-JAVA并行框架Fork/Join(三):在任务中抛出异常
在java当中,异常一共分为两种.一种是运行时异常,一种是非运行是异常. 非运行时异常:这些异常必须在方法上通过throws子句抛出.或者在方法体内进行try{…}catch{…}来捕获异常. 运行时 ...
- Atitit.加密算法 des aes 各个语言不同的原理与解决方案java php c#
Atitit.加密算法 des aes 各个语言不同的原理与解决方案java php c# 1. 加密算法的参数::算法/模式/填充 1 2. 标准加密api使用流程1 2.1. Md5——16bi ...
- PHPCMS 后台学习
1.final 不能被子类改写,不可扩展2.私有不能被继承3.构造方法,第一个被调用的方法4.static访问 类名::方法名 parent::test();这里test可以不静态 m=模块名& ...
- HTTP Range header
http://stackoverflow.com/questions/3303029/http-range-header *************************** 58 down vot ...
- IntelliJ IDEA常用快捷键小结
IntelliJ Idea 常用快捷键列表 Ctrl+Alt+t 选择代码块 try catch Alt+回车 导入包,自动修正Ctrl+N 查找类Ctrl+Shift+N 查找文件Ctrl+Alt+ ...
- 用node.js进行微信公众平台的开发
基本原理 用nodejs怎样来实现对微信公众平台的开发呢? 别的就不多说了,先来简单介绍微信公众平台的基本原理. 微信服务器就相当于一个转发服务器,终端(手机.Pad等)发起请求至微信服务器,微信服务 ...
- linux—jdk 安装步骤
1. 查看现有版本 java -version 2. 查看jdk的具体版本 rpm –qa| grep jdk rpm –qa| grep gcj 3. ...
- sublime3 10款必备插件
http://www.cnblogs.com/lhb25/p/10-essential-sublime-text-plugins.html