Kir*_*ran 10 cocoa-touch objective-c nsdate ios
如何比较两个不同的日期以找出哪个日期更晚?例如,date1
我将在下载一些数据后存储一个日期,然后date2
,我将存储当前日期.然后我需要检查哪一个更大/更晚:类似的东西if(date1>date2)
.
Dav*_*e F 25
就像是:
NSDate* timeNow = [NSDate date];
// If less than 30 seconds, do something
if ([timeNow timeIntervalSinceDate:anEarlierTime] < 30.0f)
{
// Do something
}
Run Code Online (Sandbox Code Playgroud)
Pgm*_*eek 24
你可以使用NSDate的compare:方法:
NSComparisonResult result = [Date2 compare:Date1];
if(result==NSOrderedAscending)
NSLog(@"Date1 is in the future");
else if(result==NSOrderedDescending)
NSLog(@"Date1 is in the past");
else
NSLog(@"Both dates are the same");
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
16798 次 |
最近记录: |