SORU
4 HAZİRAN 2009, PERŞEMBE


Nasıl Objective-C, iki tarih karşılaştırmak için

İki tarih var: 2009-05-11 ve geçerli bir tarih. Verilen tarih geçerli bir tarih olup olmadığını kontrol etmek istiyorum. Bu nasıl mümkün olabilir.

CEVAP
15 HAZİRAN 2009, PAZARTESİ


Cocoa has couple of methods for this:

NSDate

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

- (NSComparisonResult)compare:(NSDate *)anotherDate ,kullandığınızda geri bunlardan bir tane edinin:

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.

örnek:

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];

Bunu Paylaş:
  • Google+
  • E-Posta
Etiketler:

YORUMLAR

SPONSOR VİDEO

Rastgele Yazarlar

  • ipsy

    ipsy

    1 EKİM 2012
  • MagmaRhino

    MagmaRhino

    16 Temmuz 2011
  • MkElite

    MkElite

    13 NİSAN 2012