func timeAgoString(postTimeInterval:TimeInterval)->String{
guard timeInterval > 0 else{return ""}
let now = Date()
let postTime = Date(timeIntervalSince1970: postTimeInterval)
let c = Calendar.current.dateComponents([.year, .month, .day, .hour, .minute, .second], from: postTime, to: now)
if let year = c.year, year > 0 { return "\(year)年前" }
else if let month = c.month, month > 0{ return "\(month)月前" }
else if let day = c.day, Int(day/7) > 0{ return "\(Int(day/7))週前" }
else if let day = c.day, day > 0{ return "\(day)日前" }
else if let hour = c.hour, hour > 0{ return "\(hour)時間前" }
else if let minute = c.minute, minute > 0{ return "\(minute)分前" }
else if let second = c.second, second > 0{ return "\(second)秒前" }
return "今"
}
More than 5 years have passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme
List of users who liked
20