Comparing an NSDate to [NSDate date]

前端 未结 3 1539
借酒劲吻你
借酒劲吻你 2021-02-08 06:05

I am trying to force a user to select a date in the future with a date picker. I obviously used the compare: method, however, when I do the following code, even if it\'s the sam

3条回答
  •  感情败类
    2021-02-08 06:57

    You can use

    [datePicker.date timeIntervalSinceNow]
    

    which returns an NSTimeInterval (just a typedef for a double, in units of seconds) which is positive for the future and negative for the past.

    As the doc says, compare provides subsecond comparison, so you can use this to force their date to be a full day later (instead of just sometime in the future).

提交回复
热议问题