zoukankan      html  css  js  c++  java
  • js获取指定时间的前几秒

    最近项目上有一个需求是:根据一张图片的拍摄时间获取到这个时间前二后三的一个五秒钟的视频信息,通过查找相关资料写了一个方法拿来记录分享一下。

    //指定时间减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;
    }

  • 相关阅读:
    操作系统学习笔记:银行家算法的回顾和训练
    操作系统学习笔记:内存学习随笔
    操作系统笔记:内存的连续管理
    操作系统笔记:内存的离散管理
    操作系统:内存管理复习ing之页面置换算法
    马原学习日记1:实践
    bootstrap简单教程
    css-6(媒体识别)
    css-5(弹性盒子)
    css-3(旋转+过渡)
  • 原文地址:https://www.cnblogs.com/xzsty/p/6665038.html
Copyright © 2011-2022 走看看