Swift UIDatePicker獲取時間
Swift 4 ,取時間有問題,改用下面方法? ??
????????let?date?=????birthday.date; ????????let?dateFormatter?=?DateFormatter() ????????dateFormatter.dateFormat?=?"yyyy年MM月dd日" ????????let?age?=?dateFormatter.string(from:?date)
Swift 4 ,取時間有問題,改用下面方法? ??
????????let?date?=????birthday.date; ????????let?dateFormatter?=?DateFormatter() ????????dateFormatter.dateFormat?=?"yyyy年MM月dd日" ????????let?age?=?dateFormatter.string(from:?date)
2017-11-03
舉報
2018-01-11
http://blog.csdn.net/shenjie_xsj/article/details/79033861這里有對Swift4中時間和日期相關處理的說明
2018-01-11
????????//從控件獲取Date
????????let?selectDate?=?birthday.date
????????//創建Calendar對象calendar(這個對象用于將Date轉為DateComponents,DateComponents可以獲取Date中的各個組成元素(包括年、月、日、時、分、秒等))
????????let?calendar?=?Calendar.current
????????//使用calendar對象的dateComponents方法將selectDate轉為DateComponents對象selectDateComponents
????????let?selectDateComponents?=?calendar.dateComponents([Calendar.Component.year],?from:?selectDate)
????????//selectDateComponents點year獲取年,類型Int
????????let?selectYear?=?selectDateComponents.year!?