NSDate in Swift
2015-10-20 本文已影响0人
calmcham
NSDate References
NSDate
NSDateFormatter
NSDateComponents
NSDateComponentFormatter
NSCalendar
String与NSDate相互转换
获取当前系统时间:
let currentDate = NSDate()
打印输出:

初始化NSDateFormatter
dateFormatter.locale = NSLocale.currentLocale()
配置不同local identifier
dateFormatter.locale = NSLocale(localeIdentifier: "el_GR" ) //french dateFormatter.locale = NSLocale(localeIdentifier: "fr_FR") //greek
配置不同的NSDate输出格式
LongStyle
FullStyle
MediumSyle
and short style
dateFormatter.dateStyle = NSDateFormatterStyle.ShortStyle convertedDate = dateFormatter.stringFromDate(currentDate)
配合不同的local identifier
配合不同的locale identifier
使用date format specifiers
format specifiers
dateFormat
Paste_Image.png
Paste_Image.png