JavaScript获取当前时间减并10分钟或几分钟


function dateLess(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() - 10 * 60 * 1000);
    //小于10前面补0
    var getMonth = (d.getMonth() + 1) < 10 ? "0"+(d.getMonth() + 1) : d.getMonth() + 1;
    var getDate = d.getDate() < 10 ? "0"+(d.getDate()) : d.getDate();
    var getHours = d.getHours() < 10 ? "0"+(d.getHours()) : d.getHours();
    var getMinutes = d.getMinutes() < 10 ? "0"+(d.getMinutes()) : d.getMinutes();
    return d.getFullYear() + "-" + getMonth + "-" + getDate + " " + getHours + ":" + getMinutes;
}
console.log(dateLess('2020-09-10 15:19'))
//结果2020-09-10 15:09

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM