2013-03-07 1 views
2

오늘부터 45 일 동안의 목표를 C - iphone에 가져오고 싶습니다. 이 동적이어야한다 ... 나는 정적 할당하지 않으려는,특정 날짜 가져 오기 - 목표 c iphone

NSString *dateStr = @"Tue, 16 April 2013 13:00:00 +0000"; 
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
[dateFormat setDateFormat:@"EE, d LLLL yyyy HH:mm:ss Z"]; 
NSDate *date = [dateFormat dateFromString:dateStr]; 
[dateFormat release]; 

그러나 : 는 나는 내가 좋아하는 뭔가를해야만 할 수 있다는 것을 알고 객관적인 C :)

의 새로운입니다. 매일 나는 *date에 오늘부터 45 일간의 날짜를 변경할 필요가있다.

+0

봐 http://stackoverflow.com/questions/5067785/how-do-i-add-1-day-to-a-nsdate –

+0

@George, 좋은 , 감사. 나는 시도 할 것이다. – lolo

+0

정적이란 무엇이며 역동적이라고 할 수 있습니까? '[NSDate date]'는 항상 동적입니다. 현재 날짜를 반환합니다. –

답변

6

이 방법으로 시도 : 여기

NSDate *today=[NSDate date]; 
NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar]; 
NSDateComponents *components=[[NSDateComponents alloc] init]; 
components.day=45; 
NSDate *targetDate =[calendar dateByAddingComponents:components toDate:today options: 0]; 
+0

나는 고마워 할 것이다. – lolo

+0

완벽하게 작동합니다. 감사합니다. – lolo