Starting with iOS 15, you can use the DateFormatter API with the new style property to format dates. Here is how you can format a date based on a specific style:
main.swift220 chars10 linesIn the above code, we first create a Date object. Then we create an instance of the DateFormatter. We set the dateStyle property to .long and timeStyle property to .none. Finally, we use the string(from:) method of the DateFormatter to format the date and store the result in the formattedDateString constant.
You can choose the dateStyle and timeStyle properties based on your specific needs. The available options for dateStyle are .none, .short, .medium, and .long and for timeStyle are .none, .short, .medium, and .long.
gistlibby LogSnag