날짜까지의 일 수를 카운트 다운하고 싶습니다. 나는 몇 시간이나 몇 분 만에 관심이 없으며, 현재 날짜에서 설정 한 날짜까지의 일 수만을 말합니다.NSDate 카운트 다운 일
NSDate *date = [NSDate date];
NSString *dateString = [date description];
// this **dateString** string will have **"yyyy-MM-dd HH:mm:ss +0530"**
// NSMutableString *mutString = dateString;
NSArray *arr = [dateString componentSeperatedByString:@" "];
// arr will have [0] -> yyyy-MM-dd, [1] -> HH:mm:ss, [2] -> +0530 (time zone)
을하지만 현재 날짜가 분, 초 단위로 시간을주고 있기 때문에 작동하지 않습니다 : 이것은 내가 노력 해왔다 것입니다. 난 정말이 코드의 많은 부분을 이해하지 못하는
//NSDate *currentDate = [[NSDate alloc] init];
NSString *start = [arr objectAtIndex:0];//[NSString stringWithFormat:@"%@", currentDate];//@"2011-11-05";
NSLog(@"%@",start);
NSString *end = @"2011-6-03";
NSDateFormatter *f = [[NSDateFormatter alloc] init];
[f setDateFormat:@"yyyy-MM-dd"];
NSDate *startDate = [f dateFromString:start];
NSDate *endDate = [f dateFromString:end];
[f release];
NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
NSDateComponents *components = [gregorianCalendar components:NSDayCalendarUnit
fromDate:startDate
toDate:endDate
options:0];
NSInteger days = [components day];
[gregorianCalendar release];
NSLog(@"%i", days);
, 내가있는 NSDate 및 포맷에 익숙하지 않다, 그러나 이것은 인터넷 코드의 한 무리의 내 조합입니다.
미리 감사드립니다.
어떻게 newDate – Andrew
을 완벽하게 설정합니까? 고마워요! – Andrew