Swift Tutorial _ Basic Technology _ type conversion (parent-child class conversion; Int, Double, string conversion)
Swift Tutorials _ Basic Technology _ Get current datetime, datetime formatting, and conversion
1. Get the current date time
var nowDate = NSDate()
var formatter = NSDateFormatter()
formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
var dateString = formatter.stringFromDate(nowDate)
println(dateString)
2. String conversion Date Time
var dateString1 = "2014-1-7"
var formatter1 = NSDateFormatter()
formatter1.dateFormat = "yyyy-M-d"
var date1 = formatter1.dateFromString(dateString1)
println(date1)
3. Date Time Conversion string
var date2 = NSDate()
var formatter2 = NSDateFormatter()
formatter2.dateFormat = "yyyy-MM-dd"
var dateString2 = formatter2.stringFromDate(date2)
println(dateString2)
Swift Tutorials _ Basic Technology _ Get current datetime, datetime formatting, and conversion