OC基础:Date
来源:互联网 发布:windows软件功能 编辑:程序博客网 时间:2024/04/29 20:29
NSDate 日期类,继承自NSObject,代表一个时间点
NSDate *date=[NSDate date];
NSLog(@"%@",date); //格林尼治时间,0时区时间
NSDate *date1=[NSDatedateWithTimeIntervalSinceNow:8*60*60];//现在的时间
NSDate *date2=[NSDatedateWithTimeIntervalSinceNow:-24*60*60];//相对格林昨天的时间
// 参数为正,表示相比较0时区的未来某个时间
// 参数为负,表示相比较0时区的过去某个时间
NSDate *date3=[NSDatedateWithTimeIntervalSinceNow:60*60*24*365+8*60*60];//明年的现在时间
NSLog(@"%@",date3);
// 时间间隔
// NSTimeInterval 返回值是以秒为单位的数据
NSDate *tomorrowDate=[NSDatedateWithTimeIntervalSinceNow:24*60*60];
NSDate *yesterdayDate=[NSDatedateWithTimeIntervalSinceNow:-24*60*60];
NSTimeInterval timeTnterval=[tomorrowDatetimeIntervalSinceDate:yesterdayDate];
NSLog(@"%.2f",timeTnterval/3600);
NSTimeInterval timeTerval2=[datetimeIntervalSince1970];//返回值是距离1970年到格林的秒数
NSDate *date4=[NSDatedateWithTimeIntervalSince1970:0+60];//表示1970.1.1到某个秒数的时间点
//NSDateFormatter 日期格式类继承自NSFormatter-NSObject 用于把NSDate按照某种格式输出,转换为NSString
// 创建一个时间格式类对象
NSDateFormatter *formatter=[[NSDateFormatteralloc]init];
// 设定日期格式
[formatter setDateFormat:@"yyyy年MM月dd日 HH时mm分ss秒"];
NSString *stringTime=[formatterstringFromDate:date];//将时间对象转换为字符串对象,默认加8小时
NSLog(@"%@",stringTime);
NSDate *date7=[formatter dateFromString:@"2015-6-22 11:51:38"];//格式必须一样,减8小时
NSLog(@"%@",date7);
- OC基础:Date
- OC---oc基础入门
- OC基础
- oc基础
- OC 基础
- OC基础
- OC基础
- OC基础
- oc基础
- OC基础
- oc基础
- OC基础
- oc基础
- OC基础
- OC基础
- OC基础
- OC基础
- oc基础
- ./cts-tradefed run error[REASON:java config is not right]
- Swift之?和!
- 编辑XML
- 【MAC使用技巧】打不开xxx.pkg,因为它来自身份不明的开发者
- 字节流转字符流
- OC基础:Date
- Mac键盘图标与对应快捷按键标志汇总
- linux中gdb的使用方法
- 打算打造一个最牛iOS培训品牌
- wp8将List对象转Json字符串用于网络传输
- MySQL存储过程
- zendstudio 汉化方法
- cobbler安装
- python函数