NSDate in Swift

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
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容