Learn how to work with dates and times in Swift, from retrieving the current date to formatting it as a string.

// Get the current date and time
let currentDate = Date()

// Format a date as a string
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let dateString = dateFormatter.string(from: currentDate)
Share this post