直接代码了:
/// 秒转换成00:00:00格式
///
/// - Parameter secounds: <#secounds description#>
/// - Returns: <#return value description#>
class func getFormatPlayTime(secounds:TimeInterval)->String{
if secounds.isNaN{
return "00:00"
}
var Min = Int(secounds / )
let Sec = Int(secounds.truncatingRemainder(dividingBy: ))
var Hour =
if Min>= {
Hour = Int(Min / )
Min = Min - Hour*
return String(format: "%02d:%02d:%02d", Hour, Min, Sec)
}
return String(format: "00:%02d:%02d", Min, Sec)
} /// 根据00:00:00时间格式,转换成秒
///
/// - Parameter str: <#str description#>
/// - Returns: <#return value description#>
class func getSecondsFromTimeStr(timeStr:String) -> Int {
if timeStr.isEmpty {
return
} let timeArry = timeStr.replacingOccurrences(of: ":", with: ":").components(separatedBy: ":")
var seconds:Int = if timeArry.count > && isPurnInt(string: timeArry[]){
let hh = Int(timeArry[])
if hh! > {
seconds += hh!**
}
}
if timeArry.count > && isPurnInt(string: timeArry[]){
let mm = Int(timeArry[])
if mm! > {
seconds += mm!*
}
} if timeArry.count > && isPurnInt(string: timeArry[]){
let ss = Int(timeArry[])
if ss! > {
seconds += ss!
}
} return seconds }
比如:
100s -> 01:40
01:40 -> 100s
enjoy~