1

How to parse date string with this format (Ex: 2012-04-12T14:23:23).
I try with this format string but It's wrong: yyyy-MM-ddThh:mm:ss.
Please help!

hungbm06
  • 1,541
  • 5
  • 23
  • 32

3 Answers3

7

You should escape the letter T:

formatter.dateFormat = @"yyyy-MM-dd'T'HH:mm:ss";
sch
  • 27,318
  • 3
  • 67
  • 82
1
NSDateFormatter *dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];

NSDate *formattedDate = [dateFormatter dateFromString:@"2008-12-3T22:11:30"];
Niko
  • 2,523
  • 1
  • 22
  • 28
1

That's ISO 8601 date format. So, the best way to do this is with a specific date parser that will make life easy for you.

That can be found here http://boredzo.org/iso8601parser/.

Also, have a search on "ISO 8601". You'll find plenty of resources and example, e.g.

What's the right way to parse an ISO8601 date in cocoa?

Is there a simple way of converting an ISO8601 timestamp to a formatted NSDate?

Community
  • 1
  • 1
Max MacLeod
  • 25,335
  • 12
  • 98
  • 129