使用SwiftDate将日期转换为多种格式 | 您所在的位置:网站首页 › 分钟转换时间格式 › 使用SwiftDate将日期转换为多种格式 |
为什么不使用this库?您可以导入NSDateTimeAgo.bundle和NSDate+Extension.swift。并将您的时间戳转换为可以说1小时17分钟,你可以这样做: let timestamp = //timestamp or time let date = Date(timeIntervalSince1970: timestamp!) let timeAgo = date.timeAgo print(timeAgo)我建议你这样做,因为它更轻量。如果你不需要“前”,那么你可以从NSDateTimeAgo.string文件中删除那些。 但你也可以不用这样如任何库秒: func secondsToHoursMinutesSeconds (seconds : Int) -> (Int, Int, Int) { return (seconds/3600, (seconds % 3600)/60, (seconds % 3600) % 60) } func secondsToHoursMinutesSeconds (seconds:Int) ->() { let (h, m, s) = secondsToHoursMinutesSeconds (seconds: seconds) print ("\(h) Hours, \(m) Minutes, \(s) Seconds") } secondsToHoursMinutesSeconds(seconds: 3000)// it would print 0 Hours, 50 Minutes, 0 Seconds您也可以适应它为您的需求(此代码是从this答案)。 |
CopyRight 2018-2019 实验室设备网 版权所有 |