'substringWithRange'에 해당되는 글 1건

  1. 2012.03.27 [아이폰] 날짜 계산, 문자열 자르기
개발도구/아이폰2012.03.27 17:41
  

러퍼런스 블로그 

http://soooprmx.com/wp/archives/2335


/*

 01 Jan 02 Feb 03 Mar 04 Apr 05 May 06 Jun 07 Jul 08 Aug 09 Sep 10 Oct 11 Nov 12 Dec

*/

//NSMakeRange 특정 길이부터 길이까지 자르기

    NSString *tempStr = [tempCre substringWithRange:NSMakeRange(3,10)];

    NSString *month = [tempCre substringWithRange:NSMakeRange(4,3)];

   

    if ([month isEqualToString:@"Jan"] ) {

        month = @"01";

    }else if ( [month isEqualToString:@"Feb"] ) {

        month = @"02";        

    }else if ( [month isEqualToString:@"Mar"] ) {

        month = @"03";

    }else if ( [month isEqualToString:@"Apr"] ) {

        month = @"04";                

    }else if ( [month isEqualToString:@"May"] ) {

        month = @"05";            

    }else if ( [month isEqualToString:@"Jun"] ) {

        month = @"06";                       

    }else if ( [month isEqualToString:@"Jul"] ) {                                        

        month = @"07";                                        

    }else if ( [month isEqualToString:@"Aug"] ) {

        month = @"08";

    }else if ( [month isEqualToString:@"Sep"] ) {

        month = @"09";

    }else if ( [month isEqualToString:@"Oct"] ) {

        month = @"10";

    }else if ( [month isEqualToString:@"Nov"] ) {

        month = @"11";

    }else if ( [month isEqualToString:@"Dec"] ) {

        month = @"12";

    }


    NSString *tempDate = [NSString stringWithFormat:@"%@%@%@",[tempCre substringWithRange:NSMakeRange(26,4)],month,[tempCre substringWithRange:NSMakeRange(8,2)]];


    NSLog(@"%@",tempDate);

    NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];

    [dateFormat setDateFormat:@"yyyyMMdd"];

    NSDate *date = [dateFormat dateFromString:tempDate];  

    

    NSLog(@"%@",date); // 2012-03-25


    //오늘 날짜 구하기

    NSDate *today = [NSDate date];

    NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] initautorelease];

    [dateFormatter setDateFormat:@"yyyyMMdd"];

    NSString *nowDate = [dateFormatter stringFromDate:today];

    NSLog(@"%@",nowDate); //20120327

    

    NSDateComponents *dateComp = [[NSCalendar currentCalendar] components:NSDayCalendarUnit fromDate:date toDate:today options:0]; //today 오늘 날짜

    NSLog(@"%d",[dateComp day]); // 현재 날짜와 비교하여 뺀 값이 나오게 됩니다. 

   


    

    tempStr = [tempStr substringWithRange:NSMakeRange(0,2)];

    if ([dateComp day] <= 4) {

     //   [[cell userCreatedLabel] setText:@"new"];    cell new text 일단 주석 이미지 대치

    [cell userCreatedLabel].hidden = NO;

    }else {

        [cell userCreatedLabel].hidden = YES;

    } 

Posted by 예배하는 프로그래머