Swift - 总秒数--换算成00:00:00
// MARK: - 把秒数转换成时分秒(00:00:00)格式
///
/// - Parameter time: time(Float格式)
/// - Returns: String格式(00:00:00)
func transToHourMinSec(time: Float) -> String
{
let allTime: Int = Int(time)
var hours = 0
var minutes = 0
var seconds = 0
var hoursText = ""
var minutesText = ""
var secondsText = ""
hours = allTime / 3600
hoursText = hours > 9 ? "\(hours)" : "0\(hours)"
minutes = allTime % 3600 / 60
minutesText = minutes > 9 ? "\(minutes)" : "0\(minutes)"
seconds = allTime % 3600 % 60
secondsText = seconds > 9 ? "\(seconds)" : "0\(seconds)"
return "\(hoursText):\(minutesText):\(secondsText)"
}
本文标题:Swift - 总秒数--换算成00:00:00
本文链接:https://www.haomeiwen.com/subject/jizdnhtx.html
网友评论