Skip to content

Instantly share code, notes, and snippets.

@alekseylichtman
Last active June 10, 2021 16:35
Show Gist options
  • Save alekseylichtman/d983c2ad63726e418c69688ea3a9d693 to your computer and use it in GitHub Desktop.
Save alekseylichtman/d983c2ad63726e418c69688ea3a9d693 to your computer and use it in GitHub Desktop.
Swift. Get Date() with timezone
extension Date {
var currentUTCTimeZoneDate: String {
let calendar = Calendar.current
let timeZone = calendar.timeZone.identifier
let formatter = DateFormatter()
formatter.timeZone = TimeZone(identifier: timeZone)
formatter.amSymbol = "AM"
formatter.pmSymbol = "PM"
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZ"
print(formatter)
return formatter.string(from: self)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment