Time comparisons in swift

后端 未结 4 1119
梦如初夏
梦如初夏 2020-12-09 20:54

Question:

I need to compare 2 times - the current time and a set one. If the set time is in the future, find out how many minutes remain until said future time.

4条回答
  •  孤街浪徒
    2020-12-09 21:42

        let dateComparisionResult: NSComparisonResult = currentDate.compare("Your Date")
    
    
        if dateComparisionResult == NSComparisonResult.OrderedAscending
        {
            // Current date is smaller than end date.
        }
        else if dateComparisionResult == NSComparisonResult.OrderedDescending
        {
            // Current date is greater than end date.
    
        }
        else if dateComparisionResult == NSComparisonResult.OrderedSame
        {
            // Current date and end date are same.
    
        }
    

提交回复
热议问题