iphone - How to format date from string? -


I have a string with this value:

  2010-05-13 23 : 17: 29  

I want to format it and using the following code:

  NSDateFormatter * formatter = [[NSDateFormatter alloc] init ]; Formatter.dateStyle = NSDateFormatterMediumStyle; NSDT * formatted date = [format dement string: datestring]; [Format release];  

When the debugger reaches the release line, then the formattedet shows "invalid thiefring ruff" and

  address 0x0  not using memory Can I have any idea what I am doing wrong? 

dateFromString is returning zero Because it could not parse the string with date and time. This is because NSDateFormatterMediumStyle specifies a date format such as "May 16, 2010" (this actually varies depending on locale and user settings). This format does not match your string.

To parse your string, you should set one instead of dateStyle , for example:

  formatter .dateFormat = @ " Yyyy-MM-dd HH: mm: SS ";  

Comments