IOS--时间 NSDate,NSTimeInterval的一些转换
//1.时间格式NSDateFormatter *_dateFormatter = [[NSDateFormatter alloc] init]; [_dateFormatter setDateFormat:@"YYYY年MM月dd天hh小时mm分ss秒"]; //2.获取系统时间NSString *date = [_dateFormatter stringFromDate:[NSDate date]]; //3.NSDate转化为时间戳NSTimeInterval a=[date timeIntervalSince1970]; //4.时间戳转化为NSDateNSDate *stampDate = [NSDate dateWithTimeIntervalSince1970:timeInter]; //4.NSDate转化为NSStringNSString* dateString = [_dateFormatter stringFromDate:date]; //5.传入时间差,重置格式 //传入时间差,转换格式- (NSString *)timeWithMessageString:(NSTimeInterval)timeInter { int month = timeInter / (3600 * 24 * 30); int day = timeInter / (3600 * 24); int hour = timeInter / 3600; int minute = timeInter / 60; int day_process = day - month * 30; int hour_process = hour - day *24; int minute_process = minute - hour *60; int miao_process = timeInter - minute*60; NSString *timedate = nil; if (day == 0) { timedate = [NSString stringWithFormat:@"%d小时%d分%d秒",hour_process,minute_process,miao_process]; if (hour == 0) { timedate = [NSString stringWithFormat:@"%d分%d秒",minute_process,miao_process]; if (hour == 0) { timedate = [NSString stringWithFormat:@"%d秒",miao_process]; } } }else{ timedate = [NSString stringWithFormat:@"%d天%d小时%d分%d秒",day_process,hour_process,minute_process,miao_process]; } timedate = [NSString stringWithFormat:@"限时优惠: 还剩%@",timedate]; return timedate; }
//当前时间的半小时后 NSDate *date1 = [NSDate date];NSDate *date2 = [[NSDate date] dateByAddingTimeInterval: 30*60];NSDate *date3 = [NSDate dateWithTimeIntervalSinceNow:30*60];
转载于:https://www.cnblogs.com/qiyiyifan/p/7602639.html
IOS--时间 NSDate,NSTimeInterval的一些转换相关推荐
- iOS时间转换相关整理(附送试用期逻辑处理)
对于时间转换我们并不陌生,只是不同的后台风格不同,我们请求回来的时间格式也不同! 现整理时间相关点: //从1970年开始到现在经过了多少秒-(NSString *)getTimeSp{NSStrin ...
- ios时间戳和日期的一些转换,如具体时间,年龄,星座等等
1. ///将时间戳转为日期时间/// @param timestamp 时间戳/// @param dateFormat 日期样式 YYYY-MM-dd HH:mm:ss+ (NSString *) ...
- iOS 时间转换总结
今天整理一下时间转换的类. 1.获取当前时间字符串 /*** 当前时间字符串** @param format 时间格式 @"yyyy-MM-dd HH:mm:ss"** @retu ...
- iOS 时间,时间戳 ,nsstring ,NSTimeInterval,日期间的比较
时间比较 - (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate; @property (readonly) NSTimeInter ...
- iOS中NSDate常用转换操作整合
//当前时间格式化, 例:YYYY-MM-dd-EEEE-HH:mm:ss + (NSString *)getCurrentDataWithDateFormate:(NSString *)format ...
- iOS 时间比较大小
转载:http://blog.csdn.net/sunnyboy9/article/details/49889923 /******* 设置两个时间差为固定值 *******/ NSCalendar ...
- iOS - OC NSDate
前言 NSDate @interface NSDate : NSObject <NSCopying, NSSecureCoding> NSDate 用来表示公历的 GMT 时间(格林威治时 ...
- IOS时间与日期处理
主要有以下类: NSDate -- 表示一个绝对的时间点 NSTimeZone -- 时区信息 NSLocale -- 本地化信息 NSDateComponents -- 一个封装了具体年月日.时秒分 ...
- iOS 时间与日期处理
主要有以下类: NSDate -- 表示一个绝对的时间点 NSTimeZone -- 时区信息 NSLocale -- 本地化信息 NSDateComponents -- 一个封装了具体年月日.时秒分 ...
最新文章
- Lambda表达式介绍
- 搭建prometheus+grafana监控系统
- SUBMIT - selscreen_parameters
- 上传漏洞学习——upload-labs 闯关(一)
- python连接clickhouse
- 匿名内部类与Lambda表达式
- 【POJ】3255 Roadblocks(次短路+spfa)
- scala的函数化编程
- Spring源码之bean的加载(二)获取单例bean
- Eclipse跌落神坛了。。
- 使用uddi sdk发布服务到UDDI时的安全配置
- PMP不报培训班的通过率高吗?
- 【UVM芯片漫游指南_000】总目录(下)——UVM目录
- Charles 弱网测试
- 尚观python培训视频教程
- pdf转换器注册码及pdf转换器使用步骤
- 投屏软件_五款良心投屏软件,将安卓iOS投射到大屏幕
- 阿里云短信验证码开发
- html里怎么画斜线表头,Word2013中绘制斜线表头的方法
- 服务器固件测试--PCI设备的介绍(集成网卡和外插网卡)
热门文章
- ipguard,IM文件传送策略
- java鼠标指针锤子,java线程工具走出锤子敲铁皮时代。
- 无需Root手机导出系统 so库
- 嵌入式 视频编码 hisi
- tree老师:PSSH自动化运维实战
- 小经验:sympy.abc最好指定导入,不要全部导入
- 1067:取石子游戏
- IDN-Fast and Accurate Single Image Super-Resolution via Information Distillation Network信息蒸馏网络
- CRT连接linux,新建的用户“oralce”可以登陆了,root就登录不了了。 /etc/ssh/sshd_config 找到 PermitRootLogin no 改为yes
- in_addr和in6_addr结构体