Skip to content

Instantly share code, notes, and snippets.

@drrost
Last active December 18, 2019 20:43
Show Gist options
  • Save drrost/0a303c8c15b69da0057eb1507a83a286 to your computer and use it in GitHub Desktop.
Save drrost/0a303c8c15b69da0057eb1507a83a286 to your computer and use it in GitHub Desktop.
extension Date {
private static let isoDateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.locale = Locale(identifier: "en_US_POSIX")
dateFormatter.timeZone = TimeZone(abbreviation: "GMT")
dateFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS"
return dateFormatter
}()
func toISOString() -> String {
Date.isoDateFormatter.string(from: self).appending("Z")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment