适合IOS新手的的倒计时显示时间格式的实用方法
首先下载第三方包 http://pan.baidu.com/s/1jGYKFlk
导入第三方包,在你需要的地方导入头文件GWHelper.h
代码如下,看起来很清晰明了的:
NSDate *time = [GWHelper convertString:@"2016/01/06/13/36/21" formatter:@"yyyy/MM/dd/HH/mm/ss"];//你要比较的时间
NSDate *now = [NSDate date];//当前时间
NSTimeInterval timeInterval = [now timeIntervalSinceDate:time];
long long temp = 0;
NSString *result;
if (timeInterval < 60) {
result = [NSString stringWithFormat:@"刚刚"];
} else if((temp = timeInterval/60) < 60){
result = [NSString stringWithFormat:@"%lld分前",temp];
} else if((temp = temp/60) < 24){
result = [NSString stringWithFormat:@"%lld小时前",temp];
} else if((temp = temp/24) < 30){
result = [NSString stringWithFormat:@"%lld天前",temp];
} else if((temp = temp/30) < 12){
result = [NSString stringWithFormat:@"%lld月前",temp];
} else {
temp = temp/12;
result = [NSString stringWithFormat:@"%lld年前",temp];
}
NSLog(@"%@",result);
就那么多吧,写这个的时间是2015/01/06/14/07/34打印结果是这样的:
2016-01-06 14:07:52.974 倒计时Test[18474:237570] 31分前
- iOS SVProgressHUD延迟提示显示时间的方法
- iOS时间以yyyy-MM-dd格式输出的两种方法代码
- json格式的时间显示Date问题解决方法
- PHP 显示当前年月日的方法集合时间戳转化为时间格式
- ios 在中国地区,24小时时间格式 系统设定下 获得12小时制时间的方法
- Asp.Net时间格式转换实用方法
- iOS UITextField 显示银行卡格式的方法
- json格式的时间显示为正常年月日的方法
- 关于IOS中时间显示格式问题为中文问题(虽然语言设置为英文)
- iOS NSDateFormatter 适合任何国家的时间格式
- json格式的时间显示为正常年月日的方法
- IOS学习 NSDateFormatter的时间显示格式
- json格式的时间显示为正常年月日的方法
- iOS 获得屏幕正在显示的Controller(自定义的控制器)的实用方法
- iOS获取当前时间日期,并按规定格式显示【原创】
- ios开发新手如何看待JSON格式数据(适合OC刚刚入门的童鞋)
- js+数组实现网页上显示时间/星期几的实用方法
- ext 可编辑grid时间格式显示的改变方法,也可用作其他的类型数据的改变
- PHP使用适合阅读的格式显示文件大小的方法
- 年月日时间格式转时间戳 ,ios系统不兼容 JS 中 = new Date(yyyy-mm-dd)方法