时间操作相关的主要类有:

NSDate

NSDatFormatter

NSCalendar

NSDateComponents


另外介绍一个定时器对象NSTimer


NSDate

用于描述一个日期时间,提供了一些基本的时间获取和比较方法

+(instancetype)date//当前日期时间+(instancetype)dateWithTimeIntervalSinceNow:(NSTimeInterval)seconds-(NSComparisonResult)compare:(NSDate*)anotherDate-(NSTimeInterval)timeIntervalSinceDate:(NSDate*)anotherDate


NSDateFormatter

用于字符串格式化NSDate对象

@property(copy)NSString*dateFormat//格式-(NSString*)stringFromDate:(NSDate*)date-(NSDate*)dateFromString:(NSString*)string


NSCalendar

日历对象,在日历对象之上,进行NSDate与NSDateComponents的转换

+(NSCalendar*)currentCalendar-(NSDateComponents*)components:(NSCalendarUnit)unitFlagsfromDate:(NSDate*)date-(NSDate*)dateFromComponents:(NSDateComponents*)comps


NSDateComponents

用于对象的方式描述NSDate对象

@propertyNSIntegeryear@propertyNSIntegermonth@propertyNSIntegerday@propertyNSIntegerhour@propertyNSIntegerminute@propertyNSIntegersecond...


NSTimer

NSTimer用于启动一个定时,定时执行指定的操作

指定的操作用SEL(方法)对象指定

//直接启动定时器+(NSTimer*)scheduledTimerWithTimeInterval:(NSTimeInterval)secondstarget:(id)targetselector:(SEL)aSelectoruserInfo:(id)userInforepeats:(BOOL)repeats//创建一个不直接启动的定时器+(NSTimer*)timerWithTimeInterval:(NSTimeInterval)secondstarget:(id)targetselector:(SEL)aSelectoruserInfo:(id)userInforepeats:(BOOL)repeats

定时器的其他控制方法:

-(void)fire//启动-(void)invalidate//使失效