Table View Cell Not Showing Date

My table view cells aren't showing the date of json files collected from NewsApi.com. Can someone pls help ? Link to project below Link to project below. In in the LatestNewsViewController

https://github.com/lexypaul13/Covid-News 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as! NewsTableViewCell

        cell.authorName.text = articles?[indexPath.row].author

        cell.headLine.text = articles?[indexPath.row].title

        cell.newsImage.downloadImage(from:(self.articles?[indexPath.item].urlImage ?? "nill"))



        if let date = articles?[indexPath.row].publishedAt{

            let dateFormatter = DateFormatter()

            dateFormatter.dateFormat = "yyyy-MM-dd"

            guard let time = dateFormatter.date(from: date) else { return cell }

            let formattedString = dateFormatter.string(from:time)

            cell.timePublication.text = formattedString

        }

        

        

 

        return cell

    }
Have you checked you get a date on line 8 ?
Could add on line 15:
Code Block
else { print("no date at ", indexPath.row) }

and tell what you get

Code Block
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell1", for: indexPath) as! NewsTableViewCell
cell.authorName.text = articles?[indexPath.row].author
cell.headLine.text = articles?[indexPath.row].title
cell.newsImage.downloadImage(from:(self.articles?[indexPath.item].urlImage ?? "nill"))
if let date = articles?[indexPath.row].publishedAt {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"
guard let time = dateFormatter.date(from: date) else { return cell }
let formattedString = dateFormatter.string(from:time)
cell.timePublication.text = formattedString
}
return cell
}

Accepted Answer
Are sure the date format for publishedAt is really "yyyy-MM-dd"?

To check if it is the right date format for publishedAt, change the following line:
Code Block
      guard let time = dateFormatter.date(from: date) else { return cell }

to the following:
Code Block
      guard let time = dateFormatter.date(from: date) else {
print("Bad date: \(date)")
return cell
}

And see what you get.
@OOPer It prints out "Bad date: 2020-08-22T18:55:36Z". Please verify that my assumption and solution to the problem is correct.
The string date doesn't match the date format because it is "yyyy-MM-dd" , I have to use a different string date to match it. Right ?

I have to use a different string date to match it. Right ?

Right.
Table View Cell Not Showing Date
 
 
Q