classTimeTool{ /// Date -> String(朋友圈时间显示格式) /// /// - Parameter with: Date /// - Returns: String staticfunctoMsgTime(withdate: Date) -> String? { let sinceDate = date let curDate =Date() let i: Int=Int(curDate.timeIntervalSince(sinceDate))
let minute: Int=60 let hour: Int= minute *60 let day: Int= hour *24 let month: Int= day *30// 平均值 let year: Int= month *12
var str ="" switch i { case0..<minute: str ="刚刚" case minute..<hour: str ="\(i/minute) 分钟前" case hour..<day: str ="\(i/hour) 小时前" case day..<month: str ="\(i/day) 天前" case month..<year: str ="\(i/month) 月前" case year..<LONG_MAX: str ="\(i/year) 年前" default: returnnil } return str } }