我想在没有秒或毫秒的情况下将日期/时间保存在 CoreData 存储中。(我正在做一些处理以缩短时间,并且杂散的秒/毫秒变成了活动扳手。)降低秒数很容易:
NSDate *now = [NSDate date];
NSDateComponents *time = [[NSCalendar currentCalendar]
components:NSHourCalendarUnit | NSMinuteCalendarUnit
| NSSecondCalendarUnit fromDate:now];
NSDate *nowMinus = [now addTimeInterval:-time.second];
// e.g. 29 Aug 10 4:43:05 -> 29 Aug 10 4:43:00
这可以很好地将秒数归零,但是我找不到可以用来将毫秒数归零的 NSMillisecondCalendarUnit,我需要这样做。有任何想法吗?谢谢。