2012-08-12 7 views
0

예를 들어 NSDate에서 시간 구성 요소를 제거해야합니다. '2012-08-12 22:15:54 +00000'의 값을 가지지 만 '2012-08NSDate에서 시간 구성 요소를 제거하지 않음

NSDate* getNDateOfWeek(int week, int day) { 

    NSDate *now = [NSDate date]; 
    NSCalendar *calendar = [[[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar] autorelease]; 
    calendar.timeZone = [NSTimeZone systemTimeZone]; 
    unsigned unitFlags = NSYearCalendarUnit|NSMonthCalendarUnit|NSDayCalendarUnit; 
    NSDateComponents *comp = [calendar components:unitFlags fromDate:now]; 
    [comp setWeekday:day]; 
    [comp setWeek: week]; 
    [comp setHour:0]; 
    NSDate *resultDate = [calendar dateFromComponents:comp]; 
    return resultDate; 

} 

어떤 도움 : -12 3시 0분 0초 00000 '

강령 내가되어 사용하고있다?

답변

0

당신은 단순히 어떤 식으로 뭔가에 대해 다음 '오늘'날짜를 찾고 있다면 당신은 다른 결과를 달성하기 위해 노력하고 있지만 될 수 있습니다

// Output -> 'Mon, Jan 16, 2012' 
- (NSString *)todaysDate 
{ 
    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init]; 
    [dateFormat setDateFormat:@"EEE MMM d Y"];  
    return [dateFormat stringFromDate:[[NSDate alloc] init]]; 
} 
관련 문제