iphone - DateFormat Conversion -
i have string in format:
2012-11-08t13:50:05.284-08:00
i need convert format:
november 8, 2012 1:50 pm,
i have identified pattern of date yyyy-mm-ddthh:mm:ss.stzd, this:
nsdateformatter *dateformat = [[nsdateformatter alloc] init]; [dateformat setdateformat:@"yyyy-mm-ddthh:mm:ss.stzd"]; nsdate *date = [dateformat datefromstring:@"2012-11-08t13:50:05.284-08:00"]; [dateformat setdateformat:@"mmmm dd, yyyy hh:mm a"]; nsstring *newdatestr = [dateformat stringfromdate:date];
could please tell me what's wrong here?
is format template correct or not?
try this:as getting valid output.
nsdateformatter *dateformat = [[nsdateformatter alloc] init]; [dateformat setdateformat:@"yyyy-mm-dd't'hh:mm:ss.s'-'s':'s"]; nsdate *date = [dateformat datefromstring:@"2012-11-08t13:50:05.250-8:00"]; [dateformat setdateformat:@"mmmm dd, yyyy hh:mm a"]; nsstring *newdatestr = [dateformat stringfromdate:date]; nslog(@"newdatestr %@", newdatestr);
Comments
Post a Comment