时间戳转换成yyyy-mm-dd

function getDate(timeData,style) {   //timeData 为时间戳  style为年月日中间拼接的样式
    var time = new Date(timeData * 1000);
    var time = time.toLocaleDateString().replace(/\d+/g,function (a,b) {
      if(a.length == 1){
        var a =  '0'+a
      }
      return a
    });
    return time.replace(/\//g,style||'-')
  };

  

posted @ 2017-03-14 18:06  iwang5566  阅读(2040)  评论(0编辑  收藏  举报