let date = Calendar.current.dateComponents(in: .current, from: Date()).date!
print(date)
The .date! at the end of the first line converts the date back to UTC.
To format the date in local time do this:
let df = DateFormatter()
df.dateStyle = .full
df.timeStyle = .full
print(df.string(from: Date()))
You have options of full, medium, long, short and none for both time and date. If this doesn't suit, you can set your own formatting
df.dateFormat = "yyyy-MM-dd HH:mm:ss.SS"
which right now would give 2021-09-11 10:14:23.33 in Sydney time. You adjust the formatting tokens to suit your own needs, e.g. MM-dd-yy HH:mm would give 09-11-21 10:14
Regards, Michaela
??? Other comments and my examples that we exchanged disappeared from the thread. Have you got things working now the way you want? I'm getting an error when trying to add a new comment to the thread below.