JavaScript将时间戳转为日期

   function  other(m){
    
    return m<10?'0'+m:m },
    // 时间蹉转换成日期
   function  time(time){
    
    
      //接收一个时间戳, time是整数,否则要parseInt转换
      let timer = new Date(time);
      let y = timer.getFullYear();
      let m = timer.getMonth()+1;
      let d = timer.getDate();
      let h = timer.getHours();
      let mm = timer.getMinutes();
      let s = timer.getSeconds();
      // return y+'-'+m+'-'+d+' '+h+':'+mm+':'+s;
	 // 我这里只获取年月日
     return y + '-' +  this.other(m) + '-' + this.other(d)
    },

猜你喜欢

转载自blog.csdn.net/Jonn1124/article/details/125625230
今日推荐