Comparing dates in Cocoa

前端 未结 2 989
走了就别回头了
走了就别回头了 2021-01-16 06:10

hi i want to know how to get current date? i want to compare current date with a date i m fetching from a plist files using following code.

NSDate *expDate =         


        
2条回答
  •  萌比男神i
    2021-01-16 06:47

    To get the current date, simply use:

    NSDate * today = [NSDate date];
    

    To compare to another date:

    if ([today compare:expirationDate] == NSOrderedAscending)
    {
        // today's date is before the expiration date
    }
    

提交回复
热议问题