Basic nsdate knowledge

Source: Internet
Author: User

1. The following methods can be used to create or Initialize an instance:

The class methods used to create an nsdate instance include:

+ (ID) date;

Returns the current time.

 

+ (ID) datewithtimeintervalsincenow :( nstimeinterval) secs;

The return value is based on the current time, and the time after secs seconds is passed.

 

+ (ID) datewithtimeintervalsincereferencedate :( nstimeinterval) secs;

The returned time is based on 2001/01/01 GMT, and the time passed by secs seconds.

 

+ (ID) datewithtimeintervalsince1970 :( nstimeinterval) secs;

The return value is based on GMT, and the time after secs seconds is passed.

 

+ (ID) distantfuture;

Returns the day of the future many years later.

For example, if you need a time value that is later than the current time (now), you can call this method. The test returns 4000/12/31 16:00:00

 

+ (ID) distantpast;

Returns a day many years ago.

For example, if you need a time value that is earlier (smaller) than the current time, you can call this method. Test returned 0001/12/31 17:00:00 BC

 

The method used to create an nsdate instance is

-(ID) addtimeinterval :( nstimeinterval) secs;

The returned result is based on the time saved in the current instance, and the time passed by secs seconds

 

The methods used to initialize an nsdate instance include:

-(ID) Init;

Initialize to the current time. Similar to the date Method

 

-(ID) initwithtimeintervalsincereferencedate :( nstimeinterval) secs;

The initialization is based on 2001/01/01 GMT, and the time after secs seconds is passed. Similar to datewithtimeintervalsincereferencedate: Method

 

-(ID) initwithtimeinterval :( nstimeinterval) secs sincedate :( nsdate *) refdate;

Initialized to refdate as the benchmark, and then the time passed by secs seconds

 

-(ID) initwithtimeintervalsincenow :( nstimeinterval) secs;

The initialization is based on the current time, and the time after secs seconds is passed.

 

 

2. The following methods are available for comparison between dates:

-(Bool) is1_todate :( nsdate *) otherdate;

Yes is returned for comparison with otherdate.

 

-(Nsdate *) earlierdate :( nsdate *) anotherdate;

Returns the date earlier than anotherdate.

 

-(Nsdate *) laterdate :( nsdate *) anotherdate;

Returns the date later than anotherdate.

 

-(Nscomparisonresult) Compare :( nsdate *) Other;

This method is called for sorting:

. Nsorderedsame is returned when the date value saved by the instance and anotherdate are the same.

. Nsordereddescending is returned when the date value saved by the instance is later than anotherdate.

. Nsorderedascending is returned when the date value saved by the instance is earlier than anotherdate.

 

 

3. The interval for retrieving data can be as follows:

-(Nstimeinterval) timeintervalsincedate :( nsdate *) refdate;

Returns the time interval between the Instance Storage Time and refdate Based on refdate.

 

-(Nstimeinterval) timeintervalsincenow;

Returns the time interval between the Instance Storage Time and the current time (now) based on the current time (now ).

 

-(Nstimeinterval) timeintervalsince1970;

Return the time interval between the Instance Storage Time and GMT based on January 1, GMT.

 

-(Nstimeinterval) timeintervalsincereferencedate;

Returns the time interval between the Instance Storage Time and the GMT value of 2001/01/01.

 

 

+ (Nstimeinterval) timeintervalsincereferencedate;

Returns the interval between the current time (now) and 2001/01/01 GMT Based on the GMT value of 2001/01/01.

 

 

4. Represent the time as a string

-(Nsstring *) description;

Time is represented in the format of YYYY-MM-DD hh: mm: SS ± hhmm.

"± Hhmm" indicates the number of hours and minutes of time zone difference with GMT. For example, if the time zone is set to Beijing, "± hhmm" is displayed as "+ 0800"

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.