WXML method prescribed time format to share the front page

Introduction: original output time, for example, 2019-08-14T11: 11: 23.9700000, formatted 2019-08-14 11:11:23;

   Originally a small program util.js file, which is formatted time approaches. But it can not be .wxml called

   And sometimes, to get data directly in the js which changes will cause some trouble, so this tool when you need the file.

First, create a time formatted file .wxs

var formatTime = function (date{
    var date = getDate(date)
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var day = date.getDate()
    var hour = date.getHours()
    var minute = date.getMinutes()
    var second = date.getSeconds()

    return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, 
           second].map(formatNumber).join(':')
}

var formatNumber = function(n{
    n = n.toString()
    return n[1] ? n : '0' + n
}

module.exports = {
    formatTime: formatTime,
    formatNumber: formatNumber
}

Second, the introduction of paper pages in need

<wxs module="tutil" src="./data.wxs"></wxs>

Third, where needed formatted call

 <text class="type">{{tutil.formatTime(item.creationTime)}}</text>

 

 

  

Guess you like

Origin www.cnblogs.com/llw1996/p/11351275.html