Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>UPDATE</strong>: As pointed out by @rmaddy, there was a misunderstanding about what <code>visit.olcreatedat</code> was. This first answer is based on the assumption that <code>visit.olcreatedat</code> is an NSDate. For an answer that assumes that <code>visit.olcreatedat</code> is an NSString containing a formatted date, read the second part of this answer.</p> <h1>visit.olcreatedat is an NSDate</h1> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Alloc the date formatter in a method that gets run only when the controller appears, and not during scroll operations or UI updates. self.outputDateFormatter = [[NSDateFormatter alloc] init]; [self.outputDateFormatter setDateFormat:@"EEEE, dd MMM yyyy HH:mm:ss z"]; } - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath: { // dequeue or create the cell... // ... // ... OLVisit *visit = [self.visits objectAtIndex:indexPath.row]; NSString * strVisitDate = [self.outputDateFormatter stringFromDate:visit.olcreatedat]; // Here you can assign the string to the right UILabel cell.textLabel.text = strVisitDate; return cell; } </code></pre> <h1>visit.olcreatedat is an NSString</h1> <p>Do you want to convert the <code>visit.olcreatedat</code> to the format <strong>EEEE, dd MMM yyyy HH:mm:ss z</strong>? If so, let's go through each step.</p> <p>First, you need to convert the <code>visit.olcreatedat</code> string (stored in <code>strVisitDate</code>) to an actual NSDate object, <code>visitDate</code>. So to make this step work, you need an NSDateFormatter that accepts the <code>visit.olcreatedat</code> format: <strong>yyyy-MM-dd HH:mm:ss z</strong>.</p> <p>Then, you want to convert the obtained <code>visitDate</code> NSDate to the format you like, so you need another NSDateFormatter, with the format <strong>EEEE, dd MMM yyyy HH:mm:ss z</strong>.</p> <pre><code>- (void)viewDidLoad { [super viewDidLoad]; // Alloc the date formatter in a method that gets run only when the controller appears, and not during scroll operations or UI updates. self.inputDateFormatter = [[NSDateFormatter alloc] init]; [self.inputDateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss z"]; self.outputDateFormatter = [[NSDateFormatter alloc] init]; [self.outputDateFormatter setDateFormat:@"EEEE, dd MMM yyyy HH:mm:ss z"]; } - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath: { // dequeue or create the cell... // ... // ... OLVisit *visit = [self.visits objectAtIndex:indexPath.row]; NSString *strVisitDate = visit.olcreatedat; NSDate *visitDate = [self.inputDateFormatter dateFromString:strVisitDate]; strVisitDate = [self.outputDateFormatter stringFromDate:visitDate]; // Here you can assign the string to the right UILabel cell.textLabel.text = strVisitDate; return cell; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload