这里只介绍NSDate的日期格式化类:NSDateFormatter
(1) 第6行代码:创建了一个时间对象,这个时间表示的是点击执行代码时的时间。
(2) 第8行代码:NSDateFormatter 是日期格式化类,通过动态方法进行格式化。
(3) 第10行代码:设置日期格式,调用了dateFormat方法(动态方法)。
日期格式要区分大小写:
年用小写yyyy表示
月用大写MM表示
日用小写dd表示
大写HH表示24小时制,小写hh表示12小时制
小写mm表示分钟
小写ss表示秒
(3) 第12行:将date装换成字符串类型 stringFromDate:date