/**
获取日期信息
- parameter i: 传参为今天开始的第几天 今天为0, 明天为1, -1则代表昨天 以此类推
- return 时间信息
*/
func getDateInfo(i: Int) -> (yearStr: String, monthStr: String, dayStr: String) {
//获取当前时间
let cuurentDate = Date.init()
//对自己需要的时间进行处理
let needTime: TimeInterval = TimeInterval(i * (24*60*60))
let needDate = cuurentDate.addingTimeInterval(needTime)
//格式化
let yearFormatter = DateFormatter()
yearFormatter.dateFormat = "yyyy"
let monthFormatter = DateFormatter()
monthFormatter.dateFormat = "MM"
let dayFormatter = DateFormatter()
dayFormatter.dateFormat = "dd"
let year = yearFormatter.string(from: needDate)
let month = monthFormatter.string(from: needDate)
let day = dayFormatter.string(from: needDate)
return (year, month, day)
}
网友评论