getDateDiff:function (dateTimeStamp) {
var minute = 60
var hour = minute * 60
var day = hour * 24
var halfamonth = day * 15
var month = day * 30
var now = Date.parse(new Date())/1000 //有些特殊 不能使用 new Date()
var diffValue = now - dateTimeStamp
if(diffValue <0){return}
var monthC =diffValue/month
var weekC =diffValue/(7*day)
var dayC =diffValue/day
var hourC =diffValue/hour
var minC =diffValue/minute
var result = ''
if(monthC >段漏= 1){
result="" + parseInt(monthC) + "月前"
}
else if(weekC>=1){
世燃备 result="" + parseInt(weekC) + "周前"
}
else if(dayC>=1){
result=""+ parseInt(dayC) +"天前"
}
else if(hourC>=1){
result=""+ parseInt(hourC) +"小时前"
}
else if(minC>=1){
result=""+ parseInt(minC) +"分钟前"
}else{
搜毁 result="刚刚"
}
return result
}//时间戳转化为几天前,几小时前,几分钟前
<van-calendar
poppable="{{ false }}"
show-confirm="{{ false }}"
formatter="{{ formatter }}"
class="calendar"
show-title="{{ 伏世false }}"
show-subtitle="{{ false }}"
>
</van-calendar>
onLoad(options){
this.CalendarShow()
}
CalendarShow() {
let _this=this
var data = {}
data.formatter = this.dayFormatter
// 渲染日历
this.setData({formatter: function (day) {
缺拆肢 let month = day.date.getMonth() + 1
御简 let date = day.date.getDate()
for(let i of list){
if(month ===i.month){
if (date === i.day) {
day.bottomInfo = '余票'+i.stock+'张'
}
}
}
return day
} })
},
一、使用来自不同页面的函数函数写在util.js页面
function formatTime(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(':')
}
function formatNumber(n) {
n = n.toString()
return n[1] ? n : '0' + n
}
module.exports = {
formatTime: formatTime,
}
使用函数
图片描做唤述
图片描述
二、使用相同页面的函数
get_productInformation: function () {
。。。。
},
getZones:function(){
this.get_productInformation
},
三、使纯知凯用app.js内定义的函数
app.js代码
//app.js
App({
onLaunch: function() {
//调用API从本地缓存中获取数据
var logs = wx.getStorageSync('logs') || []
logs.unshift(Date.now())
wx.setStorageSync('logs', logs)
},
get_a_test:function(){
console.log('this is a test')
},
getUserInfo: function(cb) {
var that = this
if (this.globalData.userInfo) {
typeof cb == "function" &&cb(this.globalData.userInfo)
} else {
//调用登录接口
wx.getUserInfo({
withCredentials: false,
success: function(res) {
that.globalData.userInfo = res.userInfo
typeof cb == "function" &&cb(that.globalData.userInfo)
}
})
}
},
globalData: {
userInfo: null,
college_change:false
}
})
在其他页面中使用
图猛帆片描述
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)