-
-
Save alfian0/6667682cb776ca4d4d9b0318597641d2 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