2011-07-15 9 views
1

ループ実行のたびにNSDATEを1日増やす必要があります。その日付をコアdata.canに保存する必要があります。どのようにすればいいか教えてください。日付はnsdictionaryとすべての内部に保存する必要があります内容はNSDictionaryのインクリメントNsdate

答えて

-1

にあなたはこのような何か使用することができなければならないべきである:

NSDate *currentDate = [NSDate date]; // This could of course be whatever date you want. 
NSDate *newDate = [[currentDate] dateByAddingTimeInterval:3600 * 24]; 
+2

-1ない毎日で86,400秒を持っています。 –

4

をBPDeveloperのソリューションは、関連する夏時間の切り替えの間を除き、動作します。たとえば、米国の任意のタイムゾーンにあり、currentDateが2011年11月6日の午前12時30分である場合、その時間に24時間を追加すると、夏時間の切り替えにより、2011年11月6日の午後11時30分になります。ここで

は、その問題を回避し、代替ソリューションです:

NSDate *currentDate = [NSDate date]; 
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar]; 
NSDateComponents *offsetComponents = [[NSDateComponents alloc] init]; 
[offsetComponents setDay:1]; 
NSDate *nextDate = [gregorian dateByAddingComponents:offsetComponents toDate: yourDate options:0];