Foundation Framework (7) Time operation

Source: Internet
Author: User

The main classes related to time operations are:

NSDate

Nsdatformatter

Nscalendar

Nsdatecomponents


Also introduces a Timer object Nstimer


    • NSDate

Used to describe a datetime, providing some basic time acquisition and comparison methods

+ (Instancetype) Date//Current date time + (Instancetype) Datewithtimeintervalsincenow: (nstimeinterval) seconds-( Nscomparisonresult) Compare: (NSDate *) anotherdate-(nstimeinterval) timeintervalsincedate: (NSDate *) anotherDate


    • NSDateFormatter

NSDate object for string formatting

@property (copy) NSString *dateformat//Format-(NSString *) Stringfromdate: (NSDate *) date-(NSDate *) Datefromstring: ( NSString *) string


    • Nscalendar

Calendar object, on top of the calendar object, to convert NSDate to Nsdatecomponents

+ (Nscalendar *) currentcalendar-(nsdatecomponents *) components: (nscalendarunit) unitflags fromdate: (nsdate*) date-( NSDate *) Datefromcomponents: (nsdatecomponents *) comps


    • Nsdatecomponents

Describes NSDate objects in a way that is used for objects

@property nsinteger year@property nsinteger month@property nsinteger day@property nsinteger hour@property NSInteger Minute@property Nsinteger Second ...


    • Nstimer

Nstimer is used to start a timer and perform the specified action at timed intervals.

The specified operation is specified with the SEL (method) object

Direct Start Timer + (Nstimer *) Scheduledtimerwithtimeinterval: (nstimeinterval) seconds target: (ID) Target selector: (SEL) Aselector UserInfo: (ID) UserInfo repeats: (BOOL) repeats//Create a timer that does not start directly + (Nstimer *) Timerwithtimeinterval: ( Nstimeinterval) seconds target: (ID) Target selector: (SEL) Aselector userInfo: (ID) UserInfo repeats: (BOOL) repeats

Other control methods of the timer:

-(void) fire//Start-(void) invalidate//disable



This article is from the "Teacheran" blog, make sure to keep this source http://annmeng.blog.51cto.com/3321237/1745755

Foundation Framework (7) Time operation

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.