Skip to content

Instantly share code, notes, and snippets.

@Pulichev
Last active March 27, 2019 04:33
Show Gist options
  • Save Pulichev/84977e9f14c5ca54253d68f84cdf3821 to your computer and use it in GitHub Desktop.
Save Pulichev/84977e9f14c5ca54253d68f84cdf3821 to your computer and use it in GitHub Desktop.
extension Date {
static func dateFromISO8601String(_ string: String) -> Date? {
var tm = Darwin.tm()
strptime(string.cString(using: String.Encoding.utf8)!, "%Y-%m-%dT%H:%M:%S", &tm)
tm.tm_isdst = -1
return Date(timeIntervalSince1970: TimeInterval(mktime(&tm)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment