javascript獲取當前時間並按照自己的格式輸出


function getDate(){
    var myDate = new Date();
    //獲取當前年
    var year = myDate.getFullYear();
    //獲取當前月
    var month = myDate.getMonth() + 1;
    //獲取當前日
    var date = myDate.getDate();
    var h = myDate.getHours(); //獲取當前小時數(0-23)
    var m = myDate.getMinutes(); //獲取當前分鍾數(0-59)
    var s = myDate.getSeconds();
   //獲取當前時間
   var now = year + '-' + conver(month) + "-" + conver(date) + " " + conver(h) + ':' + conver(m) + ":" + conver(s);
}
//日期時間處理
function conver(s) {
  return s < 10 ? '0' + s : s;
}
//打印輸出
console.log(getDate());

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM