objective c - Convert NSString to NSDate results in NULL -


i want convert following date: 2010-02-01t13:58:58.513z

which stored in nsstringto , nsdate.

the following shows "null" in debugger

nsdateformatter *formatter = [[nsdateformatter alloc] init];  [formatter setdateformat:@"yyyy-mm-ddthh:mm:ss.tttz"];  nslog(@"output: %@", [formatter datefromstring:@"2010-02-01t13:58:58.513z"]);  [formatter release]; 

ideas?

you have escape "t" in format string single quotes.

[formatter setdateformat:@"yyyy-mm-dd't'hh:mm:ss.tttz"]; 

--

edit: formatters aren't correct either. ttt instance not valid formatter according documentation. official documentation

if can work, doesn't solve z problem:

nsdateformatter *formatter = [[nsdateformatter alloc] init]; [formatter setdateformat:@"yyyy-mm-dd't'hh:mm:ss.sss"]; nslog(@"output: %@", [formatter datefromstring:@"2010-02-01t13:58:58.513"]); [formatter release]; 

--

edit 2: bingo, found correct formatter.

[formatter setdateformat:@"yyyy-mm-dd't'hh:mm:ss.sss'z'"]; 

Comments

Popular posts from this blog

unicode - Are email addresses allowed to contain non-alphanumeric characters? -

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -