ios - How to correctly display date time fetched from Core Data -


- (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section {     id <nsfetchedresultssectioninfo> thesection = [[self.fetchedresultscontroller sections] objectatindex:section];      //return [[[thesection name]componentsseparatedbystring:@"+"]objectatindex:0];      return [nsdateformatter localizedstringfromdate:[nsdate datewithtimeintervalsince1970:[thesection name]] datestyle:nsdateformattermediumstyle timestyle:nsdateformatternostyle]; } 

i want use nsdateformatter display date time fetched core data , display required.

update 1

nsdateformatter *f = [[nsdateformatter alloc]init]; [f setdateformat:@"dd:mm:yy hh:mm"]; nsdate *d = [f datefromstring:[thesection name]];  return [f stringfromdate:d]; 

this not working :(

update 2

nslog(@"test=>%@",[thesection name]); 

displaying 2013-05-09 11:58:28 +0000 in database store this

389773826.504289 

this should work:

nsdateformatter *f = [[nsdateformatter alloc]init]; [f setdateformat:@"mm:dd:yy hh:mm"];  // current section: id <nsfetchedresultssectioninfo> sectioninfo = [[self.controller sections] objectatindex:section]; // 1 arbitrary object in section: nsmanagedobject *obj = [[sectioninfo objects] objectatindex:0]; // date value of object (and objects of section): nsdate *date = [obj valueforkey:@"date"]; // <-- use "sectionnamekeypath" here  return [f stringfromdate:date]; 

reason: use date attribute sectioning table view. [sectioninfo name] converts date string, makes difficult convert date different format. approach accesses date value directly, , converts desired format.


Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -