直接代码了:

 /// 秒转换成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~

Swift3 根据秒数获取视频时长(转换成00:00:00时间格式)以及将时长转换成秒的更多相关文章

  1. nginx日志修改时间格式为年月日时分秒

    先解除这段注释,使用自定义日志格式 $time_iso8601 生成格式:--20T09::+: $time_local 生成格式: /Apr/::: + 还是选择年月日时分秒看起来舒服一点

  2. LINUX 下时间转换为秒数

    linux下时间是从1970.1.1开始算的秒数 //转来自网址 http://blog.csdn.net/wind19/article/details/6579495 $ dateTue Feb 3 ...

  3. python获取指定时间段内的随机不重复的时间点

    上篇 <python时间时分秒与秒数的互相转换>http://www.cnblogs.com/gayhub/p/6154707.html 提到了把时间转成秒数的方法, 这篇写写转换成秒数后 ...

  4. GPS校时器,GPS时钟装置,NTP网络时间服务器

    GPS校时器,GPS时钟装置,NTP网络时间服务器 GPS校时器,GPS时钟装置,NTP网络时间服务器 GPS校时器,GPS时钟装置,NTP网络时间服务器 GPS校时器,GPS时钟装置,NTP网络时间 ...

  5. java 代码获取视频时长

    package test; import it.sauronsoftware.jave.Encoder; import it.sauronsoftware.jave.MultimediaInfo; i ...

  6. Android开发 获取视频中的信息(例如预览图或视频时长) MediaMetadataRetriever媒体元数据检索器

    前言 在Android里获取视频的信息主要依靠MediaMetadataRetriever实现 获取最佳视频预览图 所谓的最佳就是MediaMetadataRetriever自己计算的 /** * 获 ...

  7. python 获取视频文件的大小,时长等

    举例说明: import os import sys import xlwt from moviepy.editor import VideoFileClip file_dir = u"G: ...

  8. PHP如何获取视频总时长与码率等信息

    利用PHP中的FFmpeg读取视频播放时长与码率等信息   function getVideoInfo($file) {    define('FFMPEG_PATH', '/usr/local/ff ...

  9. vue 获取视频时长

    参考资料:js获取上传音视频文件的时长 直接通过element-ui自带的上传组件结合js即可,代码如下: HTML: <el-upload class="upload-demo&qu ...

随机推荐

  1. Path Sum II leetcode java

    题目: Given a binary tree and a sum, find all root-to-leaf paths where each path's sum equals the give ...

  2. ORM数据库框架 SQLite 常用数据库框架比较 MD

    Markdown版本笔记 我的GitHub首页 我的博客 我的微信 我的邮箱 MyAndroidBlogs baiqiantao baiqiantao bqt20094 baiqiantao@sina ...

  3. CentOS7安装openjdk、tomcat和mysql流程介绍

    首先是前戏,推荐一个远程工具Xshell和Xftp搭配使用,以下是Xshell的官网 http://www.netsarang.com/products/xsh_overview.html 1.ope ...

  4. Tensorflow动态seq2seq使用总结(r1.3)

    https://www.jianshu.com/p/c0c5f1bdbb88 动机 其实差不多半年之前就想吐槽Tensorflow的seq2seq了(后面博主去干了些别的事情),官方的代码已经抛弃原来 ...

  5. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  6. spring boot与spring mvc的区别是什么?

    Spring 框架就像一个家族,有众多衍生产品例如 boot.security.jpa等等.但他们的基础都是Spring 的 ioc和 aop ioc 提供了依赖注入的容器 aop ,解决了面向横切面 ...

  7. bash和shell的关系

    bash是borne again shell的缩写,它是shell的一种,Linux上默认采用的是bash. shell脚本中的方法带不带function的区别,例如: function foo () ...

  8. C++ 第十课:标准c时间与日期函数

    asctime() 时间文本格式 clock() 返回自程序开始运行所经过的时间 ctime() 返回特定格式时间 difftime() 两时刻的间隔 gmtime() 返回指向当前格林威治时间的指针 ...

  9. 用Eclipse进行远程Debug代码 (转)

    来自:http://blog.csdn.net/fyq891014/article/details/7534711 首先你本地Eclipse上要有和部署在远程服务器一至的项目,否则debug的时候会出 ...

  10. 纯正商业级小程序开发(完结版).txt

        链接: https://pan.baidu.com/s/1LzlDslKxSUy3UV9o1aDKhg 提取码: sq7e 文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢迎留言.评论