-4

I am having Date like "payment_date" = "03:12:00 May 06, 2014 MDT";.
But i want to convert this data into NSDate like "06-05-2014"

Please help me, don't know to handle it..

i got the answer from Converting NSString to NSDate (and back again)

 __block NSDate *detectedDate;

//Detect.
NSDataDetector *detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingAllTypes error:nil];
[detector enumerateMatchesInString:t_date
                           options:kNilOptions
                             range:NSMakeRange(0, [t_date length])
                        usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop)
{ detectedDate = result.date;

    NSDate *d=result.date;

}


 ];
Community
  • 1
  • 1

1 Answers1

-2

EDITS

NSString *str = @"03:12:00 October 06, 2014 MDT";
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setLocale:[NSLocale localeWithLocaleIdentifier:@"en_US_POSIX"]];
[df setDateStyle:NSDateFormatterLongStyle];

str = [str substringFromIndex:9];
NSDate *date = [df dateFromString:[str substringToIndex:[str length] -3]];
[df setDateFormat:@"dd-MM-YYYY"];
NSLog(@"%@",[df stringFromDate:date]);
DipakSonara
  • 2,598
  • 3
  • 29
  • 34