write the function in wxml
<wxs module="replyTime">
module.exports = function(value) {
if (!value) {
return ''
}
var date = new Date(value)
var time = new Date().getTime() - date.getTime() // - = =
if (time < 0) {
return ''
} else if ((time / 1000 < 30)) {
return ''
} else if (time / 1000 < 60) {
return parseInt((time / 1000)) + ''
} else if ((time / 60000) < 60) {
return parseInt((time / 60000)) + ''
} else if ((time / 3600000) < 24) {
return parseInt(time / 3600000) + ''
} else if ((time / 86400000) < 31) {
return parseInt(time / 86400000) + ''
} else if ((time / 2592000000) < 12) {
return parseInt(time / 2592000000) + ''
} else {
return parseInt(time / 31536000000) + ''
}
}
console.log(replyTime('2018-04-26T09:51:19.808Z')) //22
}
</wxs>
if there is a better way, please share
the landlord is actually talking about filters, which can be used in templates or even functions directly in both vue.js and angular.js.
but not Mini Program.
there are two general choices:
give two more tips:
this is the ios system, add this value = value.replace (/-/ g,'/') before the let date = new Date (value) of timeChange.
1. First of all, Mini Program needs to use the getDate function to generate the date object, which returns an object of the current time.
2. Mini Program let will report an error
module.exports = function (value) {
if (!value) {
return ''
}
var date = getDate(value)
var time = getDate().getTime() - date.getTime() // - = =
if (time < 0) {
return ''
} else if ((time / 1000 < 30)) {
return ''
} else if (time / 1000 < 60) {
return parseInt((time / 1000)) + ''
} else if ((time / 60000) < 60) {
return parseInt((time / 60000)) + ''
} else if ((time / 3600000) < 24) {
return parseInt(time / 3600000) + ''
} else if ((time / 86400000) < 31) {
return parseInt(time / 86400000) + ''
} else if ((time / 2592000000) < 12) {
return parseInt(time / 2592000000) + ''
} else {
return parseInt(time / 31536000000) + ''
}
}
<wxs src="./ccc.wxs" module="time" />
<view>{{time('2018-04-26T09:51:19.808Z')}}</view>
Test this is achievable
Previous: @ media screen and (min-width:1020px) and @ media (min-width:1020px) have no effect
Next: Now there is a web web page. If you want to adapt to the mobile terminal, please give me some ideas.