Swift教程_基础技术_获取当前日期时间、日期时间格式化及转换
Swift教程_基础技术_类型转换(父子类转换;Int、Double、String转换)
Swift教程_基础技术_获取当前日期时间、日期时间格式化及转换
1.获取当前日期时间
var nowDate = NSDate() var formatter = NSDateFormatter() formatter.dateFormat = "yyyy-MM-dd HH:mm:ss" var dateString = formatter.stringFromDate(nowDate) println(dateString)
2.字符串转换日期时间
var dateString1 = "2014-1-7" var formatter1 = NSDateFormatter() formatter1.dateFormat = "yyyy-M-d" var date1 = formatter1.dateFromString(dateString1) println(date1)
3.日期时间转换字符串
var date2 = NSDate() var formatter2 = NSDateFormatter() formatter2.dateFormat = "yyyy-MM-dd" var dateString2 = formatter2.stringFromDate(date2) println(dateString2)
文章来自:http://blog.csdn.net/ooppookid/article/details/42506957