//wxml文件内容如下
<wxs module="m1">
// utils.wxs
var time1 = getDate()
var formatTime = function (d) {
console.log("ss",time1.toString());
console.log("dd",d.toString())
var year = d.getFullYear();
var month = d.getMonth() + 1;
var day = d.getDate();
var hour = d.getHours();
var minute = d.getMinutes();
console.log('3', [year, month, day].map(formatNumber).join("-") + " " + [hour, minute].map(formatNumber).join(':'));
return ([year, month, day].map(formatNumber).join("-") + " " + [hour, minute].map(formatNumber).join(':'));
}
var formatNumber = function (n) {
n = n.toString();
return n[1] ? n : "0" + n;
}
module.exports = {
formatTime: formatTime,
time1: time1
}
</wxs>
<view style="color: red;">{{m1.formatTime(m1.time1)}}</view>
<!-- 下一语句中以时间作语量主调用Wxs函数没有返回相应的转换结果 -->
<view style="color: rgb(68, 0, 255);">m1.formatTime(time) {{m1.formatTime(time)}}</view>
<view style="color: rgb(68, 0, 255);">{{time}}</view>
//以下为JS 文件内容
<wxs module="m1">
// utils.wxs
var time1 = getDate()
var formatTime = function (d) {
console.log("ss",time1.toString());
console.log("dd",d.toString())
var year = d.getFullYear();
var month = d.getMonth() + 1;
var day = d.getDate();
var hour = d.getHours();
var minute = d.getMinutes();
console.log('3', [year, month, day].map(formatNumber).join("-") + " " + [hour, minute].map(formatNumber).join(':'));
return ([year, month, day].map(formatNumber).join("-") + " " + [hour, minute].map(formatNumber).join(':'));
}
var formatNumber = function (n) {
n = n.toString();
return n[1] ? n : "0" + n;
}
module.exports = {
formatTime: formatTime,
time1: time1
}
</wxs>
<view style="color: red;">{{m1.formatTime(m1.time1)}}</view>
<!-- 下一语句中以时间作语量主调用Wxs函数没有返回相应的转换结果 -->
<view style="color: rgb(68, 0, 255);">m1.formatTime(time) {{m1.formatTime(time)}}</view>
<view style="color: rgb(68, 0, 255);">{{time}}</view>
//下面是运行结果