Skip to content

Instantly share code, notes, and snippets.

@danielpi
Created February 19, 2018 06:14
Show Gist options
  • Save danielpi/cac52b0e83cfd49f78b03b79f4284b0f to your computer and use it in GitHub Desktop.
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
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