NSDate
以2001/01/01 GMT为基准时间,返回实例保存的时间与2001/01/01 GMT的时间间隔
- (NSTimeInterval)timeIntervalSinceReferenceDate;
初始化为当前时间。类似date方法
- (id)init;
初始化为以2001/01/01 GMT为基准,然后过了secs秒的时间。
- (id)initWithTimeIntervalSinceReferenceDate:(NSTimeInterval)secs;
NSDate (NSExtendedDate)
初始化为以2001/01/01 GMT为基准,然后过了secs秒的时间。
- (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate;
以当前时间(Now)为基准时间,返回实例保存的时间与当前时间(Now)的时间间隔
- (NSTimeInterval)timeIntervalSinceNow;
以当前时间(Now)为基准时间,返回实例保存的时间与1970/01/01 GMT的时间的时间间隔
- (NSTimeInterval)timeIntervalSince1970;
返回以目前的实例中保存的时间为基准,然后过了secs秒的时间
- (id)addTimeInterval:(NSTimeInterval)secs;
以某个时间为标准,加上若干秒后的时间
NSDate *date2 = [date1 dateByAddingTimeInterval:60];
与anotherDate比较,返回较早的那个日期
- (NSDate *)earlierDate:(NSDate *)anotherDate;
与anotherDate比较,返回较晚的那个日期
- (NSDate *)laterDate:(NSDate *)anotherDate;
该方法用于排序时调用:
(1)当实例保存的日期值与anotherDate相同时返回NSOrderedSame
(2) 当实例保存的日期值晚于anotherDate时返回NSOrderedDescending
(3) 当实例保存的日期值早于anotherDate时返回NSOrderedAscending
- (NSComparisonResult)compare:(NSDate *)other;
判断两个时间是否相同
- (BOOL)isEqualToDate:(NSDate *)otherDate;
将时间表示成字符串
以YYYY-MM-DD HH:MM:SS ±HHMM
的格式表示时间。
其中 “±HHMM” 表示与GMT的存在多少小时多少分钟的时区差异。比如,若时区设置在北京,则 “±HHMM” 显示为 “+0800”
- (NSString *)description;
NSLocale *locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]];
NSDate *today = [[NSDate date] descriptionWithLocale:locale];
返回以2001/01/01 GMT
为基准,然后过了secs秒的时间
+ (id)dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)secs;
NSDate (NSDateCreation)
返回的当前时间(now)
NSDate *date = [NSDate date];
返回当前时间secs秒后的时间
+ (instancetype)dateWithTimeIntervalSinceNow:(NSTimeInterval)secs;
返回以2001/01/01 GMT为
基准,然后过了secs秒的时间
+ (id)dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)secs;
返回以1970/01/01 GMT
为基准,然后过了secs秒的时间
+ (instancetype)dateWithTimeIntervalSince1970:(NSTimeInterval)secs;
一个NSDate对象加减一个以秒为单位的数e
+ (instancetype)dateWithTimeInterval:(NSTimeInterval)secsToBeAdded sinceDate:(NSDate *)date;
随机返回一个比较遥远的未来时间
date = [NSDate distantFuture];
随机返回一个比较遥远的过去时间
date = [NSDate distantPast];
初始化为以当前时间为基准,然后过了secs秒的时间
- (id)initWithTimeIntervalSinceNow:(NSTimeInterval)secs;
返回以1970/01/01 GMT
为基准,然后过了secs秒的时间
- (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)secs;
Returns an NSDate object initialized relative to another given date by a given number of seconds.
返回一个NSDate对象,这个对象是另一个NSDate对象加减一个以秒为单位的数的结果。
- (instancetype)initWithTimeInterval:(NSTimeInterval)secsToBeAdded sinceDate:(NSDate *)date;
推荐阅读
http://blog.youkuaiyun.com/xinshou_jiaoming/article/details/7068328
http://blog.youkuaiyun.com/daiyelang/article/details/18731543