小程序在頁面中使用的兼容ios的時間處理

最近在作小程序。又遇到了一個老問題,後臺返回的時間格式,如2018-09-08 10:00:00,直接處理成9月8日 10:00 在ios中報NAN。處理方式想在頁面中直接進行處理。ios

  1. 新建.wxss文件

因爲wxss不支持es6,因此不能使用es6語法es6

var filter = {
    formDate: function (date1) {
            if (!date1) return ''
            var reg = getRegExp('-', "g");
            var date2= date1.replace(reg, '/');
            var date = getDate(date2);
            return (date.getMonth() + 1) + "月" + date.getDate() + '日 ' + (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':' + (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes());
      }
    }
    module.exports = {
      formDate: filter.formDate
    }
  1. 在頁面中的引用
<wxs module="filter" src="../../utils/common.wxs"></wxs>
 <text class='gray'>{{filter.formDate(item.openDate)}}</text>
相關文章
相關標籤/搜索