新建以wxs结尾的文件,将以下代码复制
var toolFr = {
formatDateAll: function (time) {
if (!time) return '';
var date = getDate(time);
console.log(date)
var M = date.getMonth() + 1;
var y = date.getFullYear();
var d = date.getDate();
var h = date.getHours();
var m = date.getMinutes();
var s = date.getSeconds();
if (M < 10) M = "0" + M;
if (d < 10) d = "0" + d;
if (h < 10) h = "0" + h;
if (m < 10) m = "0" + m;
if (s < 10) s = "0" + s;
return y + '-' + M + '-' + d + ' ' + h + ':' + m + ':' + s;
},
}
module.exports = {
formatDateAll: toolFr. formatDateAll
}
wxml文件中引入方式,放在首行
<wxs module="toolFr" src="../../../../utils/filter/filter.wxs" />
在需要的地方使用方式,busJackTime为时间戳
<view class="time1" wx:if="{{busJackTime}}">{{toolFr.formatDateAll(busJackTime)}}</view>
将时间转换成时间戳
//日期转时间戳
timestamp(){
let time = '2021-08-01 19:00';
let date = new Date(time).getTime()
// let time1 = date.getTime();
console.log(date) // 1627815600000
},
网友评论