OC : NSDate (时间)

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.csdn.net/xinshou_jiaoming/article/details/7068328

http://blog.csdn.net/daiyelang/article/details/18731543

http://www.2cto.com/kf/201308/233877.html

http://www.genshuixue.com/i-cxy/p/11599618

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值