How to compare current date to previous date in iphone?

前端 未结 4 1636
夕颜
夕颜 2021-01-04 21:17

I would like to compare the current date with another date, and if that is date is earlier than the current date, then I should stop the next action. How can I do this?

4条回答
  •  甜味超标
    2021-01-04 22:00

    You can have a closer look at this Tutorial about NSDateFormatter and when you have your NSDate object you can compare it to another NSDate and get an NSTimeInterval which is the difference in seconds.

    NSDate *nowDate = [NSDate date];
    NSTimeInterval interval = [nowDate timeIntervalSinceDate:pastDate];
    

提交回复
热议问题