IOS-Frameworks-Foundation-NSDate
来源:互联网 发布:安装淘宝的npm镜像 编辑:程序博客网 时间:2024/05/19 20:57
NSDate
1:[NSDatedate]得到的时间是格林威治时间。
2:- (id) dateByAddingTimeInterval : (NSTimeInterval) ti NS_AVAILABLE(10_6,2_0);返回一个增加ti秒数后的时间。
3:- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate;返回两个时间的秒数差
如:NSTimeInterval inter = [date1timeIntervalSinceDate:date2];如果date1比date2早则返回一个负值。
例如如下代码:
//2014-11-02 22:11:49.449 YYY[796:303] 2014-11-02 14:11:49 +0000
NSDate *date1 = [NSDatedate];NSLog(@"%@",date1);
//看上面的代码段你会发现,输出的并不是当前北京时间。
//2014-11-02 22:11:49.449 YYY[796:303] 2014-11-02 14:28:29 +0000
date1 = [date1 dateByAddingTimeInterval:1000];NSLog(@"%@",date1);
NSDate *date2 = [NSDatedate];NSTimeInterval inter = [date2 timeIntervalSinceDate:date1];
//也许你会以为输出的是-1000,其实基本上不会,特别是打断点的情况下,那就取决于date1 = [date1 dateByAddingTimeInterval:1000];这段代码执行时间与NSDate *date2 = [NSDate date];这段代码执行时间之间的差距了,即使没有断点,输出也不是-1000,例如: -999.999462等。
NSLog(@"%f",inter);
4:- (NSTimeInterval) timeIntervalSinceReferenceDate;返回GMT时间2001年1月1日与对象时间之间的秒差。
//self.myDate是在另一个地方初始化的
NSTimeInterval inter2 = [self.myDatetimeIntervalSinceReferenceDate];
//返回GMT时间2001年1月1日与对象时间之间的秒差。
NSLog(@"%f",inter2);
5:- (NSComparisonResult)compare:(NSDate *)other;比较两个时间点。如果两个参数中有一个为空,结果都是0。正常情况是结果为0表示相等的意思,如果结果为-1则表示升序的意思。
NSComparisonResult compareresult = [self.myDatecompare:date1];
NSLog(@"%li",compareresult);
/*
//当self.myDate为空的时候,输出的是0。
2014-11-02 22:29:56.749 YYY[999:303] (null),2014-11-02 14:46:36 +0000
2014-11-02 22:29:58.874 YYY[999:303] 0
*/
NSComparisonResult compareresult2 = [date1compare:self.myDate];
NSLog(@"%li",compareresult2);
/*
2014-11-02 22:32:59.999 YYY[1060:303] 0//当self.myDate为空的时候,输出的是0。
*/
- IOS-Frameworks-Foundation-NSDate
- IOS-Frameworks-Foundation-NSDateFormatter
- IOS-Frameworks-Foundation-NSTimeZone
- IOS-Frameworks-Foundation-NSFileManager.h
- IOS-Frameworks-Foundation-NSNotification.h
- IOS-Frameworks-Foundation-NSPathUtilities.h 文件夹路径
- iOS-Foundation框架(NSDate.h解读)
- foundation-NSDate
- Foundation中的NSDate
- 28- -NSDate-foundation
- Foundation框架--- NSDate、NSNumber
- Foundation框架 - NSDate类
- Foundation -- OC集合 --NSDate
- Foundation Framework 日期 NSDate
- IOS Frameworks
- IOS-Frameworks-Foundation-NSDateComponents+NSCalendar 处理2月30号,12:66分类似的时间。
- foundation框架基础 NSDate-日期
- 【Foundation学习笔记】时间NSDate
- el表达式
- 技德科技宣布与Android-x86项目官方合作 并推出多款安卓PC
- 菜鸟进化每日总结之Set、Map集合
- android编码规范小结
- Struts2-037 exp 检测脚本
- IOS-Frameworks-Foundation-NSDate
- Selenium对于对话框alert,confirm,prompt的处理
- Lasso regression 和 Ridge Regression
- mongoDB
- java学习--第三篇构造函数和this关键字
- 4001
- UserControl 和 WinForm 的互動
- OkHttp详细使用
- Java NIO使用及原理分析 (一)