there is a function where option NSDate is specified putting up manually. How can I prevent execution of the function with the parameter of time, less than the current time? I have tried this
if ([currentDate timeIntervalSinceDate: myTime] < 0)
but unfortunately sometimes it doesn't work Thanks in advance.
Another option is to convert both the date to timeIntervals using timeIntervalSince1970
int interval1 = [date1 timeIntervalSince1970];
int interval2 = [date2 timeIntervalSince1970];
if(interval1 > interval2) //etc...
It sounds like you want to compare the current date with your custom date. More specifically, if the current date takes place after myTime, then the condition should be true.
if ([[NSDate date] compare: myTime] == NSOrderedDescending) {
NSLog(@"Current date is later than myTime");
}
To the opposite, you would check the comparison against NSOrderedAscending
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.