2012-11-22 4 views
0

2012-10-31T21 : 38 : 00 + 05 : 내가 문자열 형식 (예 : "2012-10-31T21의 날짜를 가지고있는 아이폰의 캘린더 응용 프로그램을 구현 한 30있는 NSDate 및 NSDateFormatter

: 38 : 00 + 05 : 30 ").

이걸 NSDate로 변환하고 싶습니다.

하지만 성공하지 못하면서 많은 노력을했습니다.

그래서이 날짜 형식을 "MM DD YYYY"로 변환하고 싶습니다.

은 아무도

+0

NSDate 개체가 필요합니까 아니면 마지막 "MM DD YYYY"문자열이 필요합니까? – rmaddy

답변

2

사용 당신 도움이

-(NSDate*)mfDateFromDotNetJSONString:(NSString *)string 
{ 
    static NSRegularExpression *dateRegEx = nil; 
    static dispatch_once_t onceToken; 
    dispatch_once(&onceToken, ^{ 
     dateRegEx = [[NSRegularExpression alloc] initWithPattern:@"^\\/date\\((-?\\d++)(?:([+-])(\\d{2})(\\d{2}))?\\)\\/$" options:NSRegularExpressionCaseInsensitive error:nil]; 
    }); 
    NSTextCheckingResult *regexResult = [dateRegEx firstMatchInString:string options:0 range:NSMakeRange(0, [string length])]; 

    if (regexResult) 
    { 
     // milliseconds 
     NSTimeInterval seconds = [[string substringWithRange:[regexResult rangeAtIndex:1]] doubleValue]/1000.0; 
     // timezone offset 
     if ([regexResult rangeAtIndex:2].location != NSNotFound) { 
      NSString *sign = [string substringWithRange:[regexResult rangeAtIndex:2]]; 
      // hours 
      seconds += [[NSString stringWithFormat:@"%@%@", sign, [string substringWithRange:[regexResult rangeAtIndex:3]]] doubleValue] * 60.0 * 60.0; 
      // minutes 
      seconds += [[NSString stringWithFormat:@"%@%@", sign, [string substringWithRange:[regexResult rangeAtIndex:4]]] doubleValue] * 60.0; 
     } 

     return [NSDate dateWithTimeIntervalSince1970:seconds]; 
    } 
    return nil; 
} 

는 희망이 기능 .... 좀 도와 줄래!