【零零散散的总结】
作者:互联网
1. 抽奖倒计时/双11倒计时
//onLoad () { setInterval(this.getRTime,1000); }
<view> {{ time }} </view>
getRTime(){ //双十一倒计时抽奖 var EndTime= new Date('2019/12/13 00:00:00'); var NowTime = new Date(); var t = EndTime.getTime() - NowTime.getTime(); if(t < 0 || t == 0) { return false } var d=Math.floor(t/1000/60/60/24); var h=Math.floor(t/1000/60/60%24); var m=Math.floor(t/1000/60%60); var s=Math.floor(t/1000%60); this.setData({ time: d + "天" + h + "时" + m + "分" + s + "秒" }) },
2. 关于时间的
const friendlyDate = timestamp => { var formats = { 'year': '%n% 年前', 'month': '%n% 月前', 'day': '%n% 天前', 'hour': '%n% 小时前', 'minute': '%n% 分钟前', 'second': '%n% 秒前', }; var now = Date.now(); console.log(now) var seconds = Math.floor((now - parseInt(timestamp)) / 1000); var minutes = Math.floor(seconds / 60); var hours = Math.floor(minutes / 60); var days = Math.floor(hours / 24); var months = Math.floor(days / 30); var years = Math.floor(months / 12); var diffType = ''; var diffValue = 0; if (years > 0) { diffType = 'year'; diffValue = years; } else { if (months > 0) { diffType = 'month'; diffValue = months; } else { if (days > 0) { diffType = 'day'; diffValue = days; } else { if (hours > 0) { diffType = 'hour'; diffValue = hours; } else { if (minutes > 0) { diffType = 'minute'; diffValue = minutes; } else { diffType = 'second'; diffValue = seconds === 0 ? (seconds = 1) : seconds; } } } } } return formats[diffType].replace('%n%', diffValue); }let time = friendlyDate('1576132494007') console.log(time) // 20秒前 2小时前。。。。。 function formatDateTime(inputTime) { var date = new Date(inputTime); var y = date.getFullYear(); var m = date.getMonth() + 1; m = m < 10 ? ('0' + m) : m; var d = date.getDate(); d = d < 10 ? ('0' + d) : d; var h = date.getHours(); h = h < 10 ? ('0' + h) : h; var minute = date.getMinutes(); var second = date.getSeconds(); minute = minute < 10 ? ('0' + minute) : minute; second = second < 10 ? ('0' + second) : second; return y + '-' + m + '-' + d+' '+h+':'+minute+':'+second; }; let time2 = formatDateTime('Thu Sep 20 2018 16:23:03 GMT+0800 (中国标准时间)') console.log(time2)
3. 不知道什么东西
wx.setNavigationBarColor({ frontColor: '#ffffff', // 状态栏+标题栏 字体颜色 backgroundColor: '#0f0' // 顶部状态栏+标题栏颜色 }) wx.setBackgroundColor({ backgroundColor: '#ffff00' // 下拉的时候看到的颜色 })
let time = +new Date() // 这里“+”相当于Number的作用,
console.log(time) // 1576132933027
标签:总结,floor,diffType,diffValue,60,var,零零散散,Math 来源: https://www.cnblogs.com/yfgg/p/12029095.html