js格式化时间戳

项目中,前端接收到后台返回的时间不是正常的格式,而是相似于这种:1560312661894前端

第一步,先转换成日期格式,以下.net

new Date(1560312661894);orm

第二步,带格式化成想要的格式,以下:get

/**
         * 格式化时间戳
         * @param {Object} now
         */
        function formatDate(now) {
          var year = now.getFullYear(),
          month = now.getMonth() + 1,
          date = now.getDate(),
          hour = now.getHours(),
          minute = now.getMinutes(),
          second = now.getSeconds();
         
          return year + "-" + month + "-" + date + " " + hour + ":" + minute + ":" + second;
        }io

相关文章
相关标签/搜索