objective c - Convert NSString to NSDate results in NULL -
i want convert following date: 2010-02-01t13:58:58.513z
which stored in nsstring
to , 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
Post a Comment