js 将时间戳转成年月日时分秒格式

 function add0(m){return m<10?'0'+m:m }
   function formatDate(needTime)
   {
  	 //needTime是整数,否则要parseInt转换
   	   var time = new Date(needTime);
   	   var y = time.getFullYear();
  	   var m = time.getMonth()+1;
  	   var d = time.getDate();
  	   var h = time.getHours();
 	  var mm = time.getMinutes();
 	  var s = time.getSeconds();
  	  return y+'-'+add0(m)+'-'+add0(d)+' '+add0(h)+':'+add0(mm)+':'+add0(s);
   }
   

你可能感兴趣的:(js 将时间戳转成年月日时分秒格式)