NSCalendar、NSDate、NSDateComponentsをうまく使用すること
//指定した日付でNSDateを作成
NSString *dateString = [[NSStringalloc] initWithFormat:@"2030/01/01 %02d:%02d:00", [cmphour], [cmpminute]];
NSDateFormatter *dateFormatter = [[NSDateFormatteralloc] init];
[dateFormatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
NSDate *date = [dateFormatter dateFromString:dateString];
[dateString relese];
[dateFormatter relese];
//現在時刻を取得
NSDate *date = [NSDate date];
//時間を追加する
NSDate *date = [NSDate date];
NSDate *newDate = [date dateByAddingTimeInterval:7*24*60*60];
//翌日に日付を取得
NSDateComponents *cmp = [[NSDateComponentsalloc] init];
[cmp setDay:1];
NSDate *date = [[NSCalendar currentCalendar] dateByAddingComponents:cmp toDate:[NSDate date] options:0];
[cmp release];
0 件のコメント:
コメントを投稿