index.html === >
<view class="countDownTimeView pull-left countDownAllView text-left">
<text>倒计时:</text>
<text class="voteText countDownTimeText">{
{countDownHour}}</text> :
<text class="voteText countDownTimeText">{
{countDownMinute}}</text> :
<text class="voteText countDownTimeText">{
{countDownSecond}}</text>
</view>
util.js === >
const formatTime = date => {
const year = date.getFullYear()
const month = date.getMonth() + 1
const day = date.getDate()
const hour = date.getHours()
const minute = date.getMinutes()
const second = date.getSeconds()
return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}
const formatNumber = n => {
n = n.toString()
return n[1] ? n : '0' + n
}
module.exports = {
formatTime: formatTime
}
index.js === >
var util = require('../../utils/util.js'); //调用微信小程序中时间格式化的js
Page: ({
data: {
countDownHour: 0, //倒计时 -时
countDownMinute: 0, //倒计时 -分
countDownSecond: 0, //倒计时-秒