将时间戳转为正常格式(2020-08-18)2020-08-18

                    function transferTime(trr) {

                      var jsonDate = new Date(parseInt(trr));

                      Date.prototype.format = function (format) {

                        var o = {

                          "y+": this.getFullYear(),

                          "M+": this.getMonth() + 1,

                          "d+": this.getDate(),

                        };

                        if (/(y+)/.test(format)) {

                          format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp

                            .$1.length));

                        }

                        for (var k in o) {

                          if (new RegExp("(" + k + ")").test(format)) {

                            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("" + o[

                              k]).substr("" + o[k].length));

                          }

                        }

                        return format;

                      };

                      var newDate = jsonDate.format("yyyy-MM-dd");

                      return newDate

                    }


                    type: 'POST',

                    contentType: "application/json;charset=utf-8",

                    headers:{'Accept': 'application/json','Authorization':'Bearer '+ solo},

                    dataType: 'json', //json 返回值类型

                    data: JSON.stringify(newsPageQO), //转化为json字符串

                    success: function (data, status) {

                        console.log(data.data.list);

                        var arr = ``;

                        for (var i = 0; i < data.data.list.length; i++) {

                          let actor = data.data.list[i].createId;

                         var trr = data.data.list[i].createTime;

                        var shijian = transferTime(trr);

                        arr = ` 

                            

                                ${data.data.list[i].id}

                                ${data.data.list[i].videoTitle}

                                ¥${data.data.list[i].videoPrice}

                                科技

                                ${shijian}

你可能感兴趣的:(将时间戳转为正常格式(2020-08-18)2020-08-18)