RELATEED CONSULTING
相关咨询
选择下列产品马上在线沟通
服务时间:8:30-17:00
你可能遇到了下面的问题
关闭右侧工具栏

新闻中心

这里有您想知道的互联网营销解决方案
Foundation框架(7)时间操作

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

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:主机域名虚拟主机、营销软件、网站建设、德州网站维护、网站推广。

    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)unitFlags fromDate:(NSDate*)date
- (NSDate *)dateFromComponents:(NSDateComponents *)comps

  • NSDateComponents

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

@property NSInteger year
@property NSInteger month
@property NSInteger day
@property NSInteger hour
@property NSInteger minute
@property NSInteger second
...

  • NSTimer

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

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

//直接启动定时器
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats
//创建一个不直接启动的定时器
+ (NSTimer *)timerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats

定时器的其他控制方法:

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


当前名称:Foundation框架(7)时间操作
网址分享:http://scyingshan.cn/article/gpphpg.html