Created
February 19, 2018 06:14
-
-
Save danielpi/cac52b0e83cfd49f78b03b79f4284b0f to your computer and use it in GitHub Desktop.
Gives you a way to create a formatted date string in one line
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 Date { | |
func usingFormat(_ format: String) -> String { | |
let dateFormatter = DateFormatter() | |
dateFormatter.dateFormat = format | |
return dateFormatter.string(from: self) | |
} | |
} | |
// Example | |
// Date().usingFormat("yyyy-MM-dd'T'HHmmss") | |
// "2018-02-19T16105" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment