我需要在特定時間段內從核心數據中獲取對象;即weekly
,monthly
,yearly
。在Objective-C的特定時間間隔內增加NSDateComponents的最佳方法是什麼?
然後我會喂從部件所產生的日期,一個predicate
這樣的:
[NSPredicate predicateWithFormat:@"(date >= %@) AND (date <= %@",
intervalStartDate, intervalEndDate];
間隔/週期的示例:
start end start end
weekly Jan 2, 2012 to Jan 08, 2012, Jan 9, 2012 to Jan 15, 2012, etc.
monthly Jan 1, 2012 to Jan 31, 2012, Feb 1, 2012 to Feb 29, 2012, etc.
yearly Jan 1, 2011 to Dec 31, 2011, Jan 1, 2012 to Dec 31, 2012, etc.
有了這些,期間,能夠得到的特定對象那段時間。
我的問題是,我不知道什麼是增加日期組件的最佳方式。我必須考慮閏年等。
實現此目標的最佳方法是什麼?
使用datecomponents打破... –