「Objective-C」日付を操作する方法のまとめ
//現在の日付
NSDate *today = [NSDate date];
//タイムゾーン
NSTimeZone *zone = [NSTimeZone systemTimeZone];
//間隔を設定
_interval = [zone secondsFromGMTForDate: today];
//明日の日付を取得
NSDate *tomorrowDate = [[NSDate alloc]initWithTimeInterval:24 * 60 * 60 sinceDate:[NSDate date]];
//カレンダー
NSCalendar *calendar = [NSCalendar currentCalendar];
//年月日
NSDateComponents *comps = [calendar components:(NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekCalendarUnit | NSWeekdayCalendarUnit |NSWeekdayOrdinalCalendarUnit | NSHourCalendarUnit) fromDate:tomorrowDate];
//weekdayを取得
NSInteger weekday = [comps weekday];
//日時をNSStringからNSDateに変換
NSDate *serverDate = [dateFomatter dateFromString:serverTimeStr];
NSDate *createDate = [dateFomatter dateFromString:createTimeStr];
//二つDate時間の間隔
NSTimeInterval betweenTime = [serverDate timeIntervalSinceDate:createDate];
//年月日分秒
NSDateFormatter *dateFomatter = [[NSDateFormatter alloc]init];
[dateFomatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
//stringをformatterに変換
NSDate *stringDate = [dateFomatter dateFromString:string];
[dateFomatter setDateFormat:@"MM-dd"];
//文字列の月日を抽出
NSString *str1 = [dateFomatter stringFromDate:stringDate];