You can use DateFormatter class to format a Date object to a string representation with a specific format.
main.swift292 chars7 linesIn the code above:
Date object representing the current date and time.DateFormatter object and set its dateFormat property to the desired format string. yyyy represents the year with four digits, MM represents the month with two digits, dd represents the day with two digits, HH represents the hour in 24-hour format with two digits, mm represents the minute with two digits, and ss represents the second with two digits.string(from:) method of the DateFormatter object to obtain the string representation of the Date object using the specified format.gistlibby LogSnag