var result_time = 45852221;
var simple_text;
switch (result_time) {
case result_time < 60:
simple_text = '刚刚';
break;
case result_time > 60 && result_time < 3600 : //分钟前
simple_text = Math.round(result_time/60)+'分钟前';
break;
case result_time > 3600 && result_time < 86400 : //小时前
simple_text = Math.round(result_time/60/24)+'小时前';
break;
case result_time > 86400 && result_time < 2592000 : //天前
simple_text = Math.round(result_time/60/60/24)+'天前';
break;
case result_time > 2592000 && result_time < 31104000 : //月前
simple_text = Math.round(result_time/60/60/24/30)+'月前';
break;
case result_time > 31104000: //年前
simple_text = Math.round(result_time/60/60/24/30/12)+'年前';
break;
}
document.write(simple_text)
如上图所示,这是一个简化时间的判断语句,为什么它判断不出任何case?
慕容森
潇湘沐
白猪掌柜的
相关分类