最近项目上有一个需求是:根据一张图片的拍摄时间获取到这个时间前二后三的一个五秒钟的视频信息,通过查找相关资料写了一个方法拿来记录分享一下。
//指定时间减2秒 function reduceTwoS(dateStr){//dateStr格式为yyyy-mm-dd hh:mm:ss var dt=new Date(dateStr.replace(/-/,"/"));//将传入的日期格式的字符串转换为date对象 兼容ie // var dt=new Date(dateStr);//将传入的日期格式的字符串转换为date对象 非ie var ndt=new Date(dt.getTime()-2000);//将转换之后的时间减去两秒 var result={ year:parseInt(ndt.getFullYear()), month:parseInt(ndt.getMonth()+1), day:parseInt(ndt.getDate()), hour:parseInt(ndt.getHours()), minute:parseInt(ndt.getMinutes()), second:parseInt(ndt.getSeconds()) } return result; }
//指定时间加3秒 function addThreeS(dateStr){//dateStr格式为yyyy-mm-dd hh:mm:ss var dt=new Date(dateStr.replace(/-/,"/"));//将传入的日期格式的字符串转换为date对象 兼容ie // var dt=new Date(dateStr);//将传入的日期格式的字符串转换为date对象 非ie var ndt=new Date(dt.getTime()+3000);//将转换之后的时间减去两秒 var result={ year:parseInt(ndt.getFullYear()), month:parseInt(ndt.getMonth()+1), day:parseInt(ndt.getDate()), hour:parseInt(ndt.getHours()), minute:parseInt(ndt.getMinutes()), second:parseInt(ndt.getSeconds()) } return result; }
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有