LoginSignup
7
10

More than 5 years have passed since last update.

日付の比較

Last updated at Posted at 2012-12-26

[NSDate compare:]を使って2つの日付を比較

    NSInteger result = [date1 compare:date2];
    switch (result) {
        case NSOrderedAscending:
            // -1
            // date1が前
            break;
        case NSOrderedSame:
            // 0
            // date1 == date2
            break;
        case NSOrderedDescending:
            // 1
            // date1が後
            break;
        default:
            break;
    }

現在時刻が、dateAとdateBの間となっているかチェック

    NSDate *now = [NSDate date];
    if ([now compare:dateA] == NSOrderedDescending && [now compare:dateB] == NSOrderedAscending) {
        return YES;
    }
    return NO;
7
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
10