Last active
December 9, 2016 15:16
-
-
Save maximbilan/125eda54bfd822da1420101595b67e4e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension Date { | |
struct Formatter { | |
static let iso8601: DateFormatter = { | |
let formatter = DateFormatter() | |
formatter.calendar = Calendar(identifier: .iso8601) | |
formatter.locale = Locale.current | |
formatter.timeZone = TimeZone(secondsFromGMT: 0) | |
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss.SSSXXXXX" | |
return formatter | |
}() | |
} | |
var iso8601: String { | |
return Formatter.iso8601.string(from: self) | |
} | |
} | |
extension String { | |
var dateFromISO8601: Date? { | |
return Date.Formatter.iso8601.date(from: self) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment