macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

years:months:days:hours:minutes:seconds:sinceDate:

2つのカレンダー日付の差を、年、月、日、時、分、秒それぞれで返します
-(void)years:(int *)yearsPointer:
        months:(int *)monthsPointer:
        days:(int *)daysPointer:
        hours:(int *)hoursPointer:
        minutes:(int *)minutesPointer:
        seconds:(int *)secondsPointer:
        sinceDate:(NSCalendarDate *)date:

解説

2つのカレンダー日付の差を、年、月、日、時、分、秒それぞれで返します。

返り値

( void )

なし

引数

( int * )yearsPointer

年の差を入れる変数のポインタ

( int * )monthsPointer

月の差を入れる変数のポインタ

( int * )daysPointer

日の差を入れる変数のポインタ

( int * )hoursPointer

時の差を入れる変数のポインタ

( int * )minutesPointer

分の差を入れる変数のポインタ

( int * )secondsPointer

秒の差を入れる変数のポインタ

( NSCalendarDate * )date

比較するカレンダー日付

クラス

NSCalendarDate

Instance Methods

使用可能

10.0

参照

- dateByAddingYears:months:days:hours:minutes:seconds:

例文

#import "MyObject.h"

@implementation MyObject

- (IBAction)myAction:(id)sender
{
int years,months,days,hours,minutes,seconds;
NSCalendarDate *theDate1;
NSCalendarDate *theDate2;
theDate1 = [NSCalendarDate dateWithYear:2001 month:1
			day:2 hour:3 minute:4 second:56 timeZone:[NSTimeZone localTimeZone]];
theDate2 = [NSCalendarDate dateWithYear:2002 month:1
			day:2 hour:3 minute:4 second:56 timeZone:[NSTimeZone localTimeZone]];

[theDate2 years:&years
            months:&months
            days:&days
            hours:&hours
            minutes:&minutes
            seconds:&seconds
            sinceDate:theDate1
            ];
                        
NSLog([NSString stringWithFormat:@"%d,%d,%d,%d,%d,%d",years,months,days,hours,minutes,seconds]);
}

@end