Created
May 28, 2015 09:15
-
-
Save hpstuff/c7f5b18a99dfaaf925f5 to your computer and use it in GitHub Desktop.
Swift
This file contains 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 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