zoukankan      html  css  js  c++  java
  • vue使用filter过滤器处理时间戳

    代码

    templelate

    <view class="comment-1-date">{{comment_1.put_time|formatDate('-')}}</view>
    

    filter

    filters: {
    	// 时间戳处理
    	formatDate: function(value, spe = '/') {
    	let time = Math.floor(((new Date()).valueOf() - value) / 86400000)
    	if (time === 0) {
    	        let time2 = Math.round(((new Date()).valueOf() - value) / 3600000)
    		if (time2 > 0) {
    		        return time2 + '小时前'
    		} else {
    			let time3=((new Date()).valueOf() - value) / 60000
    			if(time3>1){
    				return Math.ceil(time3) + '分钟前'
    			}else{
    				return Math.ceil(((new Date()).valueOf() - value)/1000)+"秒前"
    			}					
    		}
    	} else if (time > 0 && time < 30) {
    		return time + '天前'
    		} else if (time >= 30) {
    			let data = new Date(value);
    			let year = data.getFullYear();
    			let month = data.getMonth() + 1;
    			let day = data.getDate();
    			let h = data.getHours();
    			let mm = data.getMinutes();
    			let s = data.getSeconds();
    			month = month > 10 ? month : "0" + month;
    			day = day > 10 ? day : "0" + day;
    			return `${year}${spe}${month}${spe}${day}`;
    		}
    	},
    },
    

    效果展示

  • 相关阅读:
    Python解释器相关知识
    简单了解下Flask
    Scoket编程
    __file__的作用
    jquery编写可折叠列表
    浑浑噩噩的一天
    js实现杨辉三角
    js闭包
    python读取word表格
    HTMLTestRunner报告
  • 原文地址:https://www.cnblogs.com/psyduck/p/14493818.html
Copyright © 2011-2022 走看看