js,vueタイムスタンプタイム,回転間隔

932 ワード

vueフィルタに書くことも方法に書くこともできますが、ここではフィルタを例1とします.タイムスタンプを2018-10-10スタイルに変更
filters:{
    timeChange:function(v){
      var newTime = new Date(v);
      var y = newTime.getFullYear();
      var m = newTime.getMonth()+1;
      var d = newTime.getDate();
       let result = y+'-'+m+'-'+d
     return result
    }
  }

2.タイムスタンプの時間間隔、ダイナミック発表後、ダイナミックに続く表示1分前、4時間前など
timeDistance(value){
			//     
			let nowt = Math.round(new Date() / 1000)
			let times = (nowt - value);
			if(times>31536000){
				return `${parseInt(times/31536000)}  `
			}else if(times>=86400&&times<31536000){
				return `${parseInt(times/86400)}  `;
			}else if(times>=3600&&times<86400){
				return `${parseInt(times/3600)}   `;
			}else if(times>60&&times<3600){
				return `${parseInt(times/60)}   `;
			}else if(times<60){return '  '}

		}