Как сравнить две даты в Objective C

Вы можете hide/Show статусную строку в Android 4.1 (уровень API 16) и выше, используя hide()/show() функциональность

     // Hide the status bar.
    ActionBar actionBar = getActionBar();
    actionBar.hide();

   // Show the status bar.
    actionBar.show();

. Более подробную информацию вы можете найти здесь https://developer.android.com/training/system-ui/status.html

http://developer.android.com/guide/topics/ui/actionbar .html

68
задан Josh Caswell 11 June 2011 в 22:58
поделиться

5 ответов

Что вам действительно нужно, так это сравнить два объекта одного типа.

  1. Создайте NSDate из строки даты (@ "2009-05-11"):
    http : //blog.evandavey.com/2008/12/how-to-convert-a-string-to-nsdate.html

  2. Если текущая дата также является строкой, сделайте ее NSDate. Если это уже NSDate, оставьте его.

2
ответ дан 24 November 2019 в 13:57
поделиться

..

NSString *date = @"2009-05-11"
NSString *nowDate = [[[NSDate date]description]substringToIndex: 10];
if([date isEqualToString: nowDate])
{
// your code
}
-2
ответ дан 24 November 2019 в 13:57
поделиться

Какао имеет несколько методов для этого :

в NSDate

– isEqualToDate:  
– earlierDate:  
– laterDate:  
– compare:

Когда вы используете - (NSComparisonResult) сравните: (NSDate *) anotherDate , вы получите одно из следующего:

The receiver and anotherDate are exactly equal to each other, NSOrderedSame
The receiver is later in time than anotherDate, NSOrderedDescending
The receiver is earlier in time than anotherDate, NSOrderedAscending.

пример:

NSDate * now = [NSDate date];
NSDate * mile = [[NSDate alloc] initWithString:@"2001-03-24 10:45:32 +0600"];
NSComparisonResult result = [now compare:mile];

NSLog(@"%@", now);
NSLog(@"%@", mile);

switch (result)
{
    case NSOrderedAscending: NSLog(@"%@ is in future from %@", mile, now); break;
    case NSOrderedDescending: NSLog(@"%@ is in past from %@", mile, now); break;
    case NSOrderedSame: NSLog(@"%@ is the same as %@", mile, now); break;
    default: NSLog(@"erorr dates %@, %@", mile, now); break;
}

[mile release];
156
ответ дан 24 November 2019 в 13:57
поделиться

Документ Intent javadoc указывает другое действие: значение имени. Используйте android.intent.action.MEDIA_MOUNTED вместо android.content.Intent.ACTION_MEDIA_MOUNTED

com / documentation / Cocoa / Reference / Foundation / Classes / NSDate_Class / Reference / Reference.html # // apple_ref / occ / instm / NSDate / compare:

3
ответ дан 24 November 2019 в 13:57
поделиться

Если вы сделаете обе даты NSDate , вы можете использовать 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");

Вы можете взгляните на документы здесь .

22
ответ дан 24 November 2019 в 13:57
поделиться