js,vueタイムスタンプタイム,回転間隔
932 ワード
vueフィルタに書くことも方法に書くこともできますが、ここではフィルタを例1とします.タイムスタンプを2018-10-10スタイルに変更
2.タイムスタンプの時間間隔、ダイナミック発表後、ダイナミックに続く表示1分前、4時間前など
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&×<31536000){
return `${parseInt(times/86400)} `;
}else if(times>=3600&×<86400){
return `${parseInt(times/3600)} `;
}else if(times>60&×<3600){
return `${parseInt(times/60)} `;
}else if(times<60){return ' '}
}