iOS NSDate
来源:互联网 发布:在线视频转码 知乎 编辑:程序博客网 时间:2024/05/17 02:24
NSDate
NSDate是时间类,可以创建一个时间点的对象。
//返回当前时间(格林尼治时间)
NSDate *currentDate = [NSDatedate];
//返回以当前时间为准的一分钟后
NSDate *date = [NSDatedateWithTimeIntervalSinceNow:60];
//返回以2001/01/01 GMT为基准,然后过了60秒的时间
NSDate *date2 = [NSDatedateWithTimeIntervalSinceReferenceDate:60];
//返回以1970/01/01 GMT为基准,然后过了60秒的时间
NSDate *date3 = [NSDatedateWithTimeIntervalSince1970:60];
//返回很多年前的一天
NSDate *date4 = [NSDatedistantPast];
//返回很多年后的一天
NSDate *date5 = [NSDatedistantFuture];
//返回date距离现在多少秒
NSTimeInterval secs = [datetimeIntervalSinceNow];
NSDateFormatter 时间戳,用于显示时间
NSTimeZone 时区类,用于时区转换
//创建时间戳
NSDateFormatter *dateFormatter = [[NSDateFormatteralloc]init];
//自定义时间的打印格式
dateFormatter.dateFormat =@"yyyy年MM月dd日 HH:mm:ss";
//设置时区为香港
dateFormatter.timeZone = [NSTimeZonetimeZoneWithAbbreviation:@"HKT"];
NSLog(@"%@",[dateFormatterstringFromDate:currentDate]);
//获取当日时间
NSDate *time = [NSDate date];
NSDateFormatter *fommater = [[NSDateFormatter alloc]init];
[fommater setDateFormat:@"yyyy-MM-dd"];
_strData = [fommater stringFromDate:time];
- iOS NSDate
- ios NSDate
- iOS NSDate
- iOS NSDate
- IOS NSDate
- iOS NSDate
- IOS NSDate
- iOS NSDate
- iOS nsdate
- ios NSDate
- iOS NSDate
- IOS NSDate
- ios 操作日期NSDate
- iOS NSDate日期加减
- iOS NSDate日期加减
- ios--NSDate格式化(随笔)
- iOS NSTimeInterval 转成 NSDate
- iOS NSTimeInterval 转成 NSDate
- C语言堆栈入门——堆和栈的区别
- 网络编程基础
- Robotium API 二次封装
- Java实现定时任务的三种方法
- UVA 12238 Anti-Rhyme Pairs(hash+二分)
- iOS NSDate
- HDU -1879-继续畅通工程
- IE兼容性问题之trim
- iOS NSNumber
- 正则表达式三
- 史上最全的央企控股上市公司一览------央企改革股票
- python代码`if not x:` 和`if x is not None:`和`if not x is None:`使用
- HDU 1800 Flying to the Mars -- 求一组数中出现频率最大的那个数出现的次数
- 关于it-ebooks.info无法下载的一种解决方法