iOS 封装一个 Date处理服务器中返回的时间
来源:互联网 发布:出发台湾软件 编辑:程序博客网 时间:2024/05/22 04:53
//处理服务器时间的接口 +(NSString *)currentTime:(NSString *)str timeFormat:(NSString *)timeFormat;
+(NSString *)currentTime:(NSString *)string timeFormat:(NSString *)timeFormat{ //把字符串转为NSdate NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:timeFormat]; NSDate *timeDate = [dateFormatter dateFromString:string]; //得到与当前时间差 NSTimeInterval timeInterval = [timeDate timeIntervalSinceNow]; timeInterval = -timeInterval; //标准时间和北京时间差8个小时 timeInterval = timeInterval - 8*60*60; long temp = 0; NSString *result; if (timeInterval < 60) { result = [NSString stringWithFormat:@"刚刚"]; } else if((temp = timeInterval/60) <60){ result = [NSString stringWithFormat:@"%ld分钟前",temp]; } else if((temp = temp/60) <24){ result = [NSString stringWithFormat:@"%ld小时前",temp]; } else if((temp = temp/24) <30){ result = [NSString stringWithFormat:@"%ld天前",temp]; } else if((temp = temp/30) <12){ result = [NSString stringWithFormat:@"%ld月前",temp]; } else{ temp = temp/12; result = [NSString stringWithFormat:@"%ld年前",temp]; } return result;}
0 0
- iOS 封装一个 Date处理服务器中返回的时间
- iOS 封装一个Model 处理返回时间
- 从服务器中返回的时间字符串(或时间戳)的一些简单处理
- 对server 返回的时间的封装处理
- ios开发-处理服务器返回的日期
- springmvc 返回json格式中date的处理
- 对java中Date(时间)的处理工具类
- Java中关于时间的处理 Date SimpleDateFormat Calendar GegorianCalendar
- Date对象中处理时间和日期的常用方法
- Angularjs中对时间格式:/Date(1448864369815)/ 的处理
- PHP 中常用的时间处理方法 date 函数
- iOS项目开发中 webView 服务器返回来一堆不标准的html 语言 处理办法
- iOS中 new Date() 返回 NaN
- JQuery返回Json日期格式的問題 jquery对时间/Date(1387900800000)进行处理
- java得到此时此刻的2个半小时后的时间,返回一个Date类型
- iOS 处理服务器返回的浮点数数据
- iOS开发服务器返回(null) 与<null>的处理
- extjs中 一种处理封装好了的json时间
- 六:java中线程范围内共享变量--ThreadLocal
- AutoLayout 中常见的错误 以及log打印出警告整理
- HDOJ-2838 Cow Sorting
- 在Surface 3上安装ubuntu 14.04.4 备忘录
- PyCharm 教程(六)自定义文件模板
- iOS 封装一个 Date处理服务器中返回的时间
- MJRefresh的简单使用
- try c++11 foreach(1)
- 209. Minimum Size Subarray Sum
- linux下cat命令详解
- 在线的免费Markdown编辑器 'MaHua'-(麻花) & MarkDown学习资料
- Material Design (一),NavigationView+DrawerLayout轻松实现侧拉菜单
- Mybatis与Hibernate的区别
- Bzoj3124 [SDO2013]直径