Skip to content

Instantly share code, notes, and snippets.

@hpstuff
Created May 28, 2015 09:15
Show Gist options
  • Save hpstuff/c7f5b18a99dfaaf925f5 to your computer and use it in GitHub Desktop.
Save hpstuff/c7f5b18a99dfaaf925f5 to your computer and use it in GitHub Desktop.
Swift
extension String {
func toDate(format: String) -> NSDate? {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = format
return dateFormatter.dateFromString(self)
}
}
extension NSDate {
func toString(format: String) -> String {
let dateFormatter = NSDateFormatter()
dateFormatter.dateFormat = format
return dateFormatter.stringFromDate(self)
}
}
var a = "17:23"
var d = a.toDate("HH:mm")
d.toString("yyyy-MM-dd HH:mm")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment