iphone - Parse a .net datetime string into a NSDate object in objective C -


I have a string that has a .NET data timeline and I call it the NSDate object Using a NSDateFormatter . I think my format string may be incorrect or something because dateFromString: method is coming back zero Anyone can help me understand the problem here?

  NSString * rawData = @ "2009-10-20T06: 01: 00-07: 00"; // Extract the colon from the time zone NSRange timezone = NSMakeRange ([length of data] - 3, 3); Parse in NSString * cleanData = [rawData stringByReplacingOccurrencesOfString: @ ":" string: @ "option: NSCaseInsensitiveSearch limits: zone]; // A formatter setup and NSDate this object NSDateFormatter * df = [[NSDateFormatter alloc] init]; [ Df setDateFormat: @ "yyyy-MM-ddThh: mm: ssZ"]; NSDate * results = [df dateFromString: cleanData]; // result is zero    

I have just tested this code and this is the job:

  NSString * rawData = @ "2009-10-20 06: 01: 00-07: 00 "; // Strip the colon outside the time zone NSR Time Shetr = Ansmkerenj ([Kchceedeta length] - 3, 3); NSString * cleanData = [rawData stringByReplacingOccurrencesOfString: @ ":" string: @ "option: NSCaseInsensitiveSearch limits: zone]; // get rid of t clear Krentata = [Safdeta Stringbiyrplesing Okurrensofstringः @ "T" with the string: @ ""]; // Set up a formatter and parse it in the NSDate object NSDateFormatter * df = [[NSDateFormatter alloc] init]; [Df setDateFormat: @ "yyyy-MM-dd hH: mm: ssZZZ"]; NSDate * Result = [df dateFromString: cleanData]; // results Ni NSLog is (@ "Results% @", result);   

Some notes

  1. Get rid of T
  2. HH 24-hour format for hours

Comments