vue中时间戳的转换

456 阅读1分钟

 checkout() {     
 var today = new Date(); //获取当前时间   
   var y = today.getFullYear(); //对象中的年份(4位数字)  
    var M = today.getMonth() + 1; //月份从0开始计数 
     var d = today.getDate(); //日 
     var h = today.getHours(); //小时  
    var m = today.getMinutes(); //分    
  var s = today.getSeconds(); //秒   
   var S = today.getMilliseconds(); //毫秒  
    var q = Math.floor((today.getMonth() + 3) / 3); //季度   
   if (d < 10) {   
     d = "0" + d;   
   }     
 if (m < 10) {  
      M = "0" + M;   
   }   
   today = y + "-" + M + "-" + d + " " + h + ":" + m + ":" + s+':'+S; //日期   
   console.log(today);    
  console.log('第'+q+'季度'); 
   }