Swift String to Date conversion from youtube API publishedAt

19 Views Asked by At

I need to convert this date string to a date object. This is the format that youtube API sends for a published at date.

2022-10-26T02:40:04.645878Z

let all_time_date = "2022-10-26T02:40:04.645878Z"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
let allTimeDate = dateFormatter.date(from: all_time_date)

I get a null value on conversion and do not know if its the .dateFormat that is incorrect

0

There are 0 best solutions below