How to display the name of the day of the week from Date() in swift

date-formatting, swift

Solution

Use this format to format it in the way you want,

let date = Date()
let format = "EEEE-dd-MMM-yyyy"
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = format

dateFormatter.string(from: date)

Problem

I am working on a project in swift where I call the international formatted date from Date() and put it into a text label. I got it to work, but I need it to also say the name of the day of the week in front of it, for example: Thursday, 11-May-2017 and I don't know the dd-MMM-yyyy format to do that, if there is one. I have searched for it but I have not found anything. I am new to swift and would greatly appreciate some assistance. So far, my code looks like this. In the view controller I have an outlet to the label just under the view controller class. ``` @IBOutlet weak var dateDisplay: UILabel! ``` Then in the override viewDidLoad() function, I have my the code that formats the system date to the international form ``` let date = Date() let formatter = DateFormatter() formatter.dateFormat = "dd-MMM-yyyy" let result = formatter.string(from: date) dateDisplay.text! = result todayDate = result ``` Then outside of the view controller class but still in the view controller I have a variable ``` var todayDate: String = ("") ``` Right now it puts "11-May-2017" into the label. I want to put "Thursday-11-May-2017" into the label. Is there any way to do that? Thank you very much.

Original source