Date and Time Handling in Swift
Learn how to work with dates and times in Swift, from retrieving the current date to formatting it as a string.
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()
print(currentDate)
// Format a date as a string
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
let dateString = dateFormatter.string(from: currentDate)
print(dateString)