私は NSString *localized_Date = minutesSinceMidnightToLocalizedTime (時間単位) を持っています
この文字列を午前 4 時 30 分、午後 10 時と取得します。
この文字列を NSDate に変換するにはどうすればよいですか? 私にお知らせください。
私は NSString *localized_Date = minutesSinceMidnightToLocalizedTime (時間単位) を持っています
この文字列を午前 4 時 30 分、午後 10 時と取得します。
この文字列を NSDate に変換するにはどうすればよいですか? 私にお知らせください。
少し長いコードであることはわかっていますが、できるだけ読みやすくしたかったのです。このコードでは、ローカライズされた文字列の代わりに minutesSinceMidnight を使用しています。
NSDate *currentDate = [NSDate date];
NSDateComponents *currentDateComponents = [calendar components:NSHourCalendarUnit | NSMinuteCalendarUnit | NSSecondCalendarUnit fromDate:currentDate];
NSDateComponents *currentDateToMidnight = [[NSDateComponents alloc] init];
[currentDateToMidnight setHour:-[currentDateComponents hour]];
[currentDateToMidnight setMinute:-[currentDateComponents minute]];
[currentDateToMidnight setSecond:-[currentDateComponents second]];
NSDate *midnight = [calendar dateByAddingComponents:currentDateToMidnight toDate:currentDate options:0];
NSDateComponents *midnightToDesiredDate = [[NSDateComponents alloc] init];
[midnightToDesiredDate setMinute:minutesSinceMidnight];
NSDate *desiredDate = [calendar dateByAddingComponents:midnightToDesiredDate toDate:midnight options:0];