get the current date in wed 23, 2023 format in swift

You can use the DateFormatter class to format the current date in the desired format. Here's the code snippet:

main.swift
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "E d, yyyy"
let currentDate = dateFormatter.string(from: Date())
print(currentDate) // outputs something like "Wed 23, 2023"
188 chars
5 lines

In this code snippet, we create a new instance of DateFormatter and set its dateFormat property to "E d, yyyy", which specifies that we want the date to be formatted as "day-of-the-week day, year" (e.g., "Wed 23, 2023").

We then call the string(from:) method of the DateFormatter instance and pass in the current date (Date()), which returns a string representation of the current date in the specified format. Finally, we print the formatted date string to the console.

gistlibby LogSnag