Skip to content

Instantly share code, notes, and snippets.

@erickva
Last active July 12, 2016 00:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erickva/2246cd3d4e478b595673a25846dbf40b to your computer and use it in GitHub Desktop.
Save erickva/2246cd3d4e478b595673a25846dbf40b to your computer and use it in GitHub Desktop.
String to Date - Date to String
//String to NSDate
var dateString = "01-02-2010"
var dateFormatter = NSDateFormatter()
//// this is imporant - we set our input date format to match our input string
dateFormatter.dateFormat = "dd-MM-yyyy"
var dateFromString = dateFormatter.dateFromString(dateString)
//NSDate to String
var formatter: NSDateFormatter()
formatter.dateFormat = "dd-MM-yyyy"
let stringDate: String = formatter.stringFromDate(NSDate())
println(stringDate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment