iOS-OC根据时间戳获取距离现在的状态(刚刚,分钟前,今天,昨天)
iOS-OC根据时间戳获取距离现在的状态(刚刚,分钟前,今天,昨天)
获取时间戳
- - (NSString *)distanceTimeWithBeforeTime:(double)beTime
- {
- NSTimeInterval now = [[NSDatedate]timeIntervalSince1970];
- double distanceTime = now - beTime;
- NSString * distanceStr;
- NSDate * beDate = [NSDatedateWithTimeIntervalSince1970:beTime];
- NSDateFormatter * df = [[NSDateFormatteralloc]init];
- [df setDateFormat:@"HH:mm"];
- NSString * timeStr = [df stringFromDate:beDate];
- [df setDateFormat:@"dd"];
- NSString * nowDay = [df stringFromDate:[NSDate date]];
- NSString * lastDay = [df stringFromDate:beDate];
- if (distanceTime < 60) {//小于一分钟
- distanceStr = @"刚刚";
- }
- else if (distanceTime <60*60) {//时间小于一个小时
- distanceStr = [NSString stringWithFormat:@"%ld分钟前",(long)distanceTime/60];
- }
- else if(distanceTime <24*60*60 && [nowDayintegerValue] == [lastDay integerValue]){//时间小于一天
- distanceStr = [NSString stringWithFormat:@"今天 %@",timeStr];
- }
- else if(distanceTime<24*60*60*2 && [nowDayintegerValue] != [lastDay integerValue]){
- if ([nowDay integerValue] - [lastDay integerValue] ==1 || ([lastDay integerValue] - [nowDayintegerValue] > 10 && [nowDayintegerValue] == 1)) {
- distanceStr = [NSString stringWithFormat:@"昨天 %@",timeStr];
- }
- else{
- [df setDateFormat:@"MM-dd HH:mm"];
- distanceStr = [df stringFromDate:beDate];
- }
- }
- else if(distanceTime <24*60*60*365){
- [df setDateFormat:@"MM-dd HH:mm"];
- distanceStr = [df stringFromDate:beDate];
- }
- else{
- [df setDateFormat:@"yyyy-MM-dd HH:mm"];
- distanceStr = [df stringFromDate:beDate];
- }
- return distanceStr;
- }
iOS-OC根据时间戳获取距离现在的状态(刚刚,分钟前,今天,昨天)的更多相关文章
- iOS之计算上次日期距离现在多久, 如 xx 小时前、xx 分钟前等
/** * 计算上次日期距离现在多久 * * @param lastTime 上次日期(需要和格式对应) * @param format1 上次日期格式 * @para ...
- iOS中利用CoreTelephony获取用户当前网络状态(判断2G,3G,4G)
前言: 在项目开发当中,往往需要利用网络.而用户的网络环境也需要我们开发者去注意,根据不同的网络状态作相应的优化,以提升用户体验. 但通常我们只会判断用户是在WIFI还是移动数据,而实际上,移动数据也 ...
- iOS中利用CoreTelephony获取用户当前网络状态(判断2G,3G,4G) by徐文棋
前言: 在项目开发当中,往往需要利用网络.而用户的网络环境也需要我们开发者去注意,根据不同的网络状态作相应的优化,以提升用户体验. 但通常我们只会判断用户是在WIFI还是移动数据,而实际上,移动数据也 ...
- iOS - OC 面向对象语法
1.类 1)根类:因为类 NSObject 是层次结构的最顶层,因此称为根类. 可以将类称为子类(subclass)和父类(superclass),也可以将类称为子类和超类. 2)分类/类别(cate ...
- ios+oc面试题
ios+oc面试题 浅复制和深复制的区别?//浅拷贝和深拷贝答案:浅层复制(copy):只复制指向对象的指针,而不复制引用对象本身.//通过对象的指针来访问这个对象深层复制(mutableCo ...
- iOS标准时间与时间戳相互转换
iOS标准时间与时间戳相互转换 (2012-07-18 17:03:34) 转载▼ 标签: ios 时间戳 标准时间 格式 设置 转化 杂谈 分类: iPhone开发 设置时间显示格式: NS ...
- ios 从网络上获取图片并在UIImageView中显示
ios 从网络上获取图片 -(UIImage *) getImageFromURL:(NSString *)fileURL { NSLog(@"执行图片下载函数"); UIIm ...
- Java根据年龄段获取对应年份起始时间戳和最终时间戳、根据生日时间戳获取月份(与数据库的时间戳处理成的月份拼接成SQL条件)
1.传入年龄段,两个值,一个最小值,一个最大值,然后获取该年龄段的两个时间戳: (1)处理时间方法: /** * 根据年龄获取时间戳(开始年龄key取0,返回一年最后一秒时间戳,时间戳大:反之结束年龄 ...
- iOS OC语言原生开发的IM模块--RChat
iOS OC语言原生开发的IM模块,用于项目中需要原生开发IM的情况,具备发送文字.表情.语音.图片.视频等完整功能,包含图片预览视频播放等功能,此项目将会长期更新如有问题可以提出,我的邮箱:fshm ...
随机推荐
- Combination Sum | & || & ||| & IV
Combination Sum | Given a set of candidate numbers (C) and a target number (T), find all unique comb ...
- Object-c 控制语句
控制语句: 分支语句 if-else 有控制机制 switch 循环语句 while do-while for 跳转语句 break,continue,goto
- Java for LeetCode 145 Binary Tree Postorder Traversal
Given a binary tree, return the postorder traversal of its nodes' values. For example: Given binary ...
- 猪八戒吃西瓜(wmelon)-排序-查找
问题 A: 猪八戒吃西瓜(wmelon) 时间限制: 1 Sec 内存限制: 64 MB提交: 30 解决: 14[提交][状态][讨论版] 题目描述 有一天,贪吃的猪八戒来到了一个大果园,果园里 ...
- Codeforces 389A (最大公约数)
Fox and Number Game Time Limit: 1000MS Memory Limit: 262144KB 64bit IO Format: %I64d & %I64u ...
- (*p)++和*(p++)和*p++的区别
* 和++优先级是同一级别,同一级别按照从右往左的顺序计算 所以: *p++等价于*(p++) #define debug(x) cout << #x << " a ...
- 查询MYSQL和查询HBASE速度比较
上一篇文章:我要上谷歌 Mysql,关系型数据库: HBase,NoSql数据库. 查询Mysql和查询HBase,到底哪个速度快呢? 与一些真正的大牛讨论时,他们说HBase写入速度,可以达到每秒1 ...
- mysql TIMESTAMP详解
navicat中设置timestamp字段的时间,默认这里填写CURRENT_TIMESTAMP,就是在插入数据的时候按照当前时间插入: 勾选根据当前时间戳更新,表示在UPDATE的时候,会根据当前时 ...
- git merge 合并分支
git merge 用来做分支合并,将其他分支中的内容合并到当前分支中.比如分支结构如下: master / C0 ---- C1 ---- C2 ---- C4 \ C3 ---- C5 \ iss ...
- 桌面窗体应用程序,FormClosing事件
private void Form1_FormClosing(object sender, FormClosingEventArgs e) { //主窗体关闭时,弹出对话框.判断对话框的返回值(即用户 ...