
如下写了两个关于时间的函数,并将它们导出,
<wxs module="m1">
var getMax = function(flightDate) {
var now = getDate().getDate()
var flDate = getDate(flightDate).getDate()
if( now <flDate ){
return '+1'
}else{
return ''
}
}
var formartTime = function(flightDate,format){
if(flightDate){
var realDate = getDate(flightDate)
function timeFormat(num) {
return num <10 ? '0' + num : num
}
var date = {
"Y": timeFormat(realDate.getFullYear()),
"M": timeFormat(realDate.getMonth() + 1),
"d": timeFormat(realDate.getDate()),
"h": timeFormat(realDate.getHours()),
"m": timeFormat(realDate.getMinutes()),
"s": timeFormat(realDate.getSeconds()),
"q": Math.floor((realDate.getMonth() + 3) / 3),
"S": realDate.getMilliseconds(),
}
if (!format) {
format = "yyyy-MM-dd hh:mm:ss"
}
if( format == 'hh:mm' ){
return date.h+':'+date.m
}else{
return date.h+':'+date.m
}
}else{
return false
}
}
module.exports.getMax = getMax
module.exports.formartTime = formartTime
</wxs>
可在页面添加如下使用:
m1.formartTime() m1.getMax()
1、首先预备好外部想要引入的外部文件,命名为util.js,并且填充固定的文件内容(普通是固定的库)。2、其次打开util.js ,持续填写重要内容将要利用的方法用module.exports给暴显露来。
3、然后将外部js放在指定的文件夹utils里(utils 规定寄存js库和数字格式化文件)。
4、最后在想要用到这个方法的js里面 require这个js,然后调用即可。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)