微信小程序前端时间格式化

当后端传的时间是2022-12-05T02:30:12.000+0000时,前端怎么进行格式化尼

在app.js中:

 timeGl = new Date(timeGl);
    let yyyy = timeGl.getFullYear();
    // getMonth方法返回的是0-11之间的数字,代表1-12月份,若想和日历的月份时间对应,需要+1。
    let month = (timeGl.getMonth() + 1);
    if(month<10){
        month = "0"+month
    }
    let day = (timeGl.getDate()<10)?("0"+timeGl.getDate()):(timeGl.getDate());
    let hours = (timeGl.getHours()<10)?("0"+timeGl.getHours()):(timeGl.getHours());
    let minutes = (timeGl.getMinutes()<10)?("0"+timeGl.getMinutes()):(timeGl.getMinutes());
    let seconds = (timeGl.getSeconds()<10)?("0"+timeGl.getSeconds()):(timeGl.getSeconds());

    let yyyyMMddHHmmss = yyyy + '-' + month + '-' + day + ' ' + hours + ':' + minutes + ':' + seconds;
    return yyyyMMddHHmmss;

在需要用到的页面:

 listCustomerAllWinPrizeOrder: function () {

      let that = this;

      wx.request({

         url: , //请求路径

         method: 'get', //请求方式

         data: {},

         success: (res) => {

            wx.hideLoading();

            if (res.data.code == 1000) {

               let list = res.data.data,

                  winPrizeList = list.winPrizeList;

               for (var i = 0; i < winPrizeList.length; i++) {
 
                 //时间格式引用

                  winPrizeList[i].addTm = app.getTimeFun(winPrizeList[i].addTm)

               }
            } else {

               //提示失败信息

               app.showToastTip(res.data.msg)

            }

         },

         fail: (res) => {

            //提示失败信息

            app.showToastTip('删除小程序重试')

         }

      });

   },

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值