zoukankan      html  css  js  c++  java
  • js某一时间加上指定时长

    function timeFormatter(d) {
            var d = new Date(d.substring(0, 4),
            d.substring(5, 7) - 1,
            d.substring(8, 10),
            d.substring(11, 13),
            d.substring(14, 16),
            d.substring(17, 19));
            d.setTime(d.getTime() + 5 * 1000);
    
            return d.getFullYear() + "-"
                + ((d.getMonth() + 1)<10?"0"+(d.getMonth() + 1):(d.getMonth() + 1))
                + "-" + (d.getDate() < 10 ? "0" + d.getDate() : d.getDate())
                + " " + (d.getHours()<10?"0"+d.getHours():d.getHours())
                + ":" + (d.getMinutes() < 10 ? "0" + d.getMinutes() : d.getMinutes())
                + ":" + (d.getSeconds() < 10 ? "0" + d.getSeconds() : d.getSeconds());
        } 

    var second=timeFormatter('2017-08-04 23:59:55');console.log(second); //2017-08-05 00:00:00

    以上代码表示给定时间加上5秒。可以根据需要将5*1000变成指定时长,注定,单位是毫秒,返回的是结果字符串

    记录编程的点滴,体会学习的乐趣
  • 相关阅读:
    CentOS7.4安装Docker
    责任链模式
    策略模式
    状态模式
    解释器模式
    备忘录模式
    中介者模式
    观察者模式
    迭代器模式
    private、default、protected和public的作用域
  • 原文地址:https://www.cnblogs.com/AduBlog/p/13892576.html
Copyright © 2011-2022 走看看