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变成指定时长,注定,单位是毫秒,返回的是结果字符串

    记录编程的点滴,体会学习的乐趣
  • 相关阅读:
    context-annotation
    bean-annotation
    K-means算法
    基于概率的分类-贝叶斯分类
    Application
    ConfigurableApplicationContext
    相关性分析
    方差分析
    Java 大写金额转换成数字
    linux 遍历文件添加index
  • 原文地址:https://www.cnblogs.com/AduBlog/p/13892576.html
Copyright © 2011-2022 走看看