iOS compare current date to specified date size

Source: Internet
Author: User

  #pragma  mark-Get Current Time-(nsdate * *formatter=[[nsdateformatter alloc]init]; [Formatter Setdateformat:  @ " dd-mm-yyyy-hhmmss   "          ];          NSString  *datetime=[formatter stringfromdate:[nsdate Date]];                    NSDate  *date = [formatter datefromstring:datetime]; NSLog ( @ " ----------currentdate =%@            " ,date);       return   date; }  

Converts the specified date (here, for example, 2016-09-30-00) to the same date format, returning the NSDate form

NSDateFormatter *dateformatter = [[NSDateFormatter alloc] init];      [Dateformatter Setdateformat: @" Dd-mm-yyyy-hhmmss " ];   *date = [Dateformatter datefromstring:@ "30-09-2016-000000"];  

Compares the current time to a specified time, returns 1 if the specified date is not reached, returns 0, or returns 1

- (int) Compareoneday: (NSDate *) oneday withanotherday: (NSDate *) Anotherday {nsdateformatter*dateformatter =[[NSDateFormatter alloc] init]; [Dateformatter Setdateformat:@"Dd-mm-yyyy-hhmmss"]; NSString*onedaystr =[Dateformatter Stringfromdate:oneday]; NSString*anotherdaystr =[Dateformatter Stringfromdate:anotherday]; NSDate*datea =[Dateformatter Datefromstring:onedaystr]; NSDate*dateb =[Dateformatter Datefromstring:anotherdaystr]; Nscomparisonresult result=[Datea Compare:dateb]; NSLog (@"date1:%@, Date2:%@", Oneday, Anotherday); if(Result = =nsordereddescending) {              //NSLog (@ "Date1 is on the future");             return 1; }          Else if(Result = =nsorderedascending) {              //NSLog (@ "Date1 is in the past");             return-1; }          //NSLog (@ "Both dates is the same");         return 0; }  

Use

iOS compare current date to specified date size

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.