Last active
January 19, 2022 09:02
-
-
Save johncodeos/6753ece609b0c96b52f5d7b21c18f250 to your computer and use it in GitHub Desktop.
Convert String date to Date
This file contains hidden or 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 String { | |
func iso8601Value() -> Date? { | |
let theDate = self | |
let formatter = DateFormatter() | |
formatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ssZZZZ" | |
let date = formatter.date(from: theDate as String) | |
return date | |
} | |
} | |
// How to use it: | |
let time = "2022-01-15T10:16:12-04:00".iso8601Value() ?? Date() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment