Comparison of iOS development dates

Source: Internet
Author: User

Get current time:

NSDate * senddate=[nsdate Date];

NSDateFormatter *dateformatter=[[nsdateformatter alloc] init];

[Dateformatter Setdateformat:@ "YYYYMMDD"];

NSString * Locationstring=[dateformatter stringfromdate:senddate];

NSLog (@ "locationstring:%@", locationstring);

[Dateformatter release];

Comparison of dates

1. Dates can be compared to determine size or equality, or you can determine the time interval between two dates. Two-day interval difference you can use the-timeintervalsincedate: method to calculate
  

    1. NSDate * now = [NSDate Date];
    2. NSDate * Anhourago = [now datebyaddingtimeinterval:-60*60];
    3. Nstimeinterval Timebetween = [now Timeintervalsincedate:anhourago];
    4. NSLog (@ "%f", Timebetween);


2. Date comparisons can also be obtained using the-timeintervalsincenow method and the current time interval
  

    1. NSDate * Anhourago = [NSDate datewithtimeintervalsincenow;-60*60];
    2. Nstimeinterval interval = [Anhourago timeintervalsincenow];
    3. NSLog (@ "%f", interval);


The 3.NSDate also provides-laterdate,-earlierdate, and compare methods to compare dates
  

    1. NSDate * now = [NSDate Date];
    2. NSDate * Anhourago = [now datebyaddingtimeinterval:-60*60];
    3. NSDate *RESULT1 = [now Laterdate:anhourago];
    4. NSDate * RESULT2 = [now Earlierdate:anhourago];
    5. Nscomparisonresult RESULT3 = [now Compare:anhourago];

Comparison of iOS development dates

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.