#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