ios - String to NSDate problems -
i can't nsdate working life of me, thought i've scanned questions on stack overflow, appreciated.
- (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { nsstring *publishedtext = [nsstring stringwithformat:@"%@", feedlocal.published]; cell.publishedlabel.text = publishedtext; return cell; }
gives me string:
2013-05-08 18:09:37 +0000
which i'm trying turn into: may 8, 2013 6:45pm
i've tried using:
nsstring *publishedtext = [nsstring stringwithformat:@"%@", feedlocal.published]; nsdateformatter *df = [[nsdateformatter alloc] init]; [df setdateformat:@"yyyy-mm-dd hh:mm:ss.ssssss"]; nsdate *datefromstring = [[nsdate alloc] init]; datefromstring = [df datefromstring:publishedtext]; cell.publishedlabel.text = datefromstring;
but doesn't work , shows warning pointer types incompatible (nsstring
nsdate_strong
). help!
from have posted, appear feedlocal.published
nsdate
.
since goal convert date string, need this:
nsdateformatter *df = [[nsdateformatter alloc] init]; [df setdateformat:@"mmmm d, yyyy h:mma"]; // matches desired format nsstring *datestring = [df stringfromdate:feedlocal.published]; cell.publishedlabel.text = datestring;
since app can used people on world, suggest setup date formatter this:
nsdateformatter *df = [[nsdateformatter alloc] init]; [df setdatestyle:nsdateformatterlongstyle]; [df settimestyle:nsdateformattershortstyle];
do instead of setting specific date format. date , time appear appropriate users of app , not in specific country.
Comments
Post a Comment