format a date in to the format october 13, 2014 in swift

You can use DateFormatter to format a date into a string with the desired format. Here's an example code snippet:

main.swift
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMMM d, yyyy"
let date = Date(timeIntervalSince1970: 1413201600) // October 13, 2014
let dateString = dateFormatter.string(from: date) // "October 13, 2014"
221 chars
5 lines

In the above code, we create a DateFormatter object and set its dateFormat property to "MMMM d, yyyy" which represents the desired date format. We then create a Date object with the desired date (here we're using the Unix timestamp for October 13, 2014) and use the dateFormatter to convert the Date object into a string representation of the date in the desired format. The resulting dateString will contain the string "October 13, 2014".

related categories

gistlibby LogSnag