Reputation: 10738
The following outputs the complete month name, e.g. July 11, 2022
Text("\(Date().now, style: .date)") // output: July 11, 2022
Is there a way to make it show just the short month name, e.g. Jul 11, 2022
or 06/11/22
?
Upvotes: 0
Views: 1426
Reputation: 257653
We have now explicit initializer for that, like
Text(Date.now, format: Date.FormatStyle(date: .abbreviated, time: .omitted))
Upvotes: 4
Reputation: 3051
Show current date without time in a short format.
//Jul 11, 2022
Text(Date().formatted(date: .abbreviated, time: .omitted))
//7/11/2022
Text(Date().formatted(date: .numeric, time: .omitted))
formatted(date:time:) (Apple Developer Documentation)
Upvotes: 2