let date = Date()
print(date) // printed date is UTC
If you are using playground, use a print statement to check the time. Playground shows local time until you print it. Do not depend on the right side panel of playground.
This code gives date in UTC. If you need the local time, you should call the following extension with timezone as Timezone.current
extension Date {
var currentUTCTimeZoneDate: String {
let formatter = DateFormatter()
formatter.timeZone = TimeZone(identifier: "UTC")
formatter.amSymbol = "AM"
formatter.pmSymbol = "PM"
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
return formatter.string(from: self)
}
}
For UTC time, use it like: Date().currentUTCTimeZoneDate