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

2021-03-28 03:25

阅读:583

标签:substr   get   log   col   turn   style   substring   nbsp   date   

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) ;
    var getDate = d.getDate() (d.getDate()) : d.getDate();
    var getHours = d.getHours() (d.getHours()) : d.getHours();
    var getMinutes = d.getMinutes() (d.getMinutes()) : d.getMinutes();
    return d.getFullYear() + "-" + getMonth + "-" + getDate + " " + getHours + ":" + getMinutes;
}
console.log(dateLess(‘2020-09-10 15:19‘))
//结果2020-09-10 15:09

 

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

标签:substr   get   log   col   turn   style   substring   nbsp   date   

原文地址:https://www.cnblogs.com/ssjd/p/13645855.html


评论


亲,登录后才可以留言!