Objective-C 基础

来源:互联网 发布:淘宝开店名字 编辑:程序博客网 时间:2024/05/17 08:19
/* NSDate.h Copyright (c) 1994-2013, Apple Inc. All rights reserved. */ #import @class NSString; FOUNDATION_EXPORT NSString * const NSSystemClockDidChangeNotification NS_AVAILABLE(10_6, 4_0); typedef double NSTimeInterval; //因为是double类型的所以输出时要用NSLog(@"%lf", timeInterval); #define NSTimeIntervalSince1970 978307200.0@interface NSDate : NSObject- (NSTimeInterval)timeIntervalSinceReferenceDate; @end @interface NSDate (NSExtendedDate) - (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate; //两个日期之间相隔多少秒 - (NSTimeInterval)timeIntervalSinceNow; // 日期距离现在相隔多少秒 - (NSTimeInterval)timeIntervalSince1970;// 日期距离1970年1月1日0点相隔多少秒 - (id)addTimeInterval:(NSTimeInterval)seconds NS_DEPRECATED(10_0, 10_6, 2_0, 4_0);//此方法已经过时了 但是效果是和下面的方法一样的 - (id)dateByAddingTimeInterval:(NSTimeInterval)ti NS_AVAILABLE(10_6, 2_0);//返回现在的时间往后ti秒 如果是负数则是往前ti秒 - (NSDate *)earlierDate:(NSDate *)anotherDate; //两个时间相比较返回较早的时间 - (NSDate *)laterDate:(NSDate *)anotherDate;//两个时间比较返回比较迟的时间 - (NSComparisonResult)compare:(NSDate *)other;//比较两个时间self比other迟返回NSOrderedAscending(-1,小于)self比other早返回NSOrderedDescending(1,大于)相等NSOrderedSame(0) - (BOOL)isEqualToDate:(NSDate *)otherDate;//返回两个时间是否相等 - (NSString *)description;//返回形容的一个字符串:2014-11-02 22:44:22 +0000 - (NSString *)descriptionWithLocale:(id)locale; + (NSTimeInterval)timeIntervalSinceReferenceDate;// 以2001/01/01 GMT为基准时间,返回实例保存的时间与2001/01/01 GMT的时间间隔 @end @interface NSDate (NSDateCreation) + (instancetype)date;//返回当前的时间 + (instancetype)dateWithTimeIntervalSinceNow:(NSTimeInterval)secs;//返回以现在的时间为基准时间,往前(secs>0)或往后(secs < 0)|secs|秒的日期 + (instancetype)dateWithTimeIntervalSinceReferenceDate:(NSTimeInterval)ti; //返回以2001/01/01 GMT的时间为基准时间,往前(secs>0)或往后(secs < 0)|secs|秒的日期 + (instancetype)dateWithTimeIntervalSince1970:(NSTimeInterval)secs; //返回以1970/01/01 GMT的时间为基准时间,往前(secs>0)或往后(secs < 0)|secs|秒的日期 + (instancetype)dateWithTimeInterval:(NSTimeInterval)secsToBeAdded sinceDate:(NSDate *)date; //返回以date 的时间为基准时间,往前(secs>0)或往后(secs < 0)|secs|秒的日期 + (id /* NSDate * */)distantFuture;// 随机返回一个比较遥远的未来时间 + (id /* NSDate * */)distantPast;// 随机返回一个比较遥远的以前时间 - (instancetype)init; /* designated initializer *///初始化 //下面的初始化和上面的一样 - (instancetype)initWithTimeIntervalSinceReferenceDate:(NSTimeInterval)ti; /* designated initializer */ - (instancetype)initWithTimeIntervalSinceNow:(NSTimeInterval)secs; - (instancetype)initWithTimeIntervalSince1970:(NSTimeInterval)secs; - (instancetype)initWithTimeInterval:(NSTimeInterval)secsToBeAdded sinceDate:(NSDate *)date; @end
0 0