美文网首页
NSDate in Swift

NSDate in Swift

作者: calmcham | 来源:发表于2015-10-20 11:04 被阅读0次

NSDate References

NSDate
NSDateFormatter
NSDateComponents
NSDateComponentFormatter
NSCalendar

String与NSDate相互转换

获取当前系统时间:
let currentDate = NSDate()
打印输出:

Paste_Image.png
初始化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

相关文章

网友评论

      本文标题:NSDate in Swift

      本文链接:https://www.haomeiwen.com/subject/bxnzcttx.html