MYF

Swift中Date类的格式化输入输出

将Date类的时间格式化输入输出

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
let start = "2016-09-28"

// Input format
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy-MM-dd"

let startDate:Date = dateFormatter.date(from: start)!
let endDate:Date = Date.init() // current date

// Output format
let fmt = DateFormatter()
fmt.dateFormat = "yyMMdd"

var date = startDate // first date
while date <= endDate {
date.addTimeInterval(60*60*24) // add a day
print(fmt.string(from: date)
}