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