JavaScript让时间显示为多久以前
答案:2 悬赏:50 手机版
解决时间 2021-02-26 04:20
- 提问者网友:你挡着我发光了
- 2021-02-26 00:54
JavaScript让时间显示为多久以前
最佳答案
- 五星知识达人网友:山君与见山
- 2021-02-26 01:57
参考下面方法
function gettime(createtime){
var now=Date.parse(new Date())/1000;
var limit=now-createtime;
var content="";
if(limit<60){
content="刚刚";
}else if(limit>=60 && limit<3600){
content=Math.floor(limit/60)+"分钟前";
}else if(limit>=3600 && limit<86400){
content=Math.floor(limit/3600)+"小时前";
}else if(limit>=86400 && limit<2592000){
content=Math.floor(limit/86400)+"天前";
}else if(limit>=2592000 && limit<31104000){
content=Math.floor(limit/2592000)+"个月前";
}else{
content="很久前";
}
return content;
}
function gettime(createtime){
var now=Date.parse(new Date())/1000;
var limit=now-createtime;
var content="";
if(limit<60){
content="刚刚";
}else if(limit>=60 && limit<3600){
content=Math.floor(limit/60)+"分钟前";
}else if(limit>=3600 && limit<86400){
content=Math.floor(limit/3600)+"小时前";
}else if(limit>=86400 && limit<2592000){
content=Math.floor(limit/86400)+"天前";
}else if(limit>=2592000 && limit<31104000){
content=Math.floor(limit/2592000)+"个月前";
}else{
content="很久前";
}
return content;
}
全部回答
- 1楼网友:夜风逐马
- 2021-02-26 03:04
var enable=0;today=new date();
var day;
var date;
var time_start=new date();
var clock_start=time_start.gettime();
if (today.getday()==0) day="日";
if (today.getday()==1) day="一";
if (today.getday()==2) day="二";
if (today.getday()==3) day="三";
if (today.getday()==4) day="四";
if (today.getday()==5) day="五";
if (today.getday()==6) day="六";
date=""+(today.getyear())+"年"+(today.getmonth()+1)+"月"+(today.getdate())+"日 星期";
document.write("<span >"+date);
document.write(day+"</span>");
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯