发布网友 发布时间:2022-04-23 22:51
共2个回答
热心网友 时间:2022-05-14 20:53
formatDate:function(date){
varnow=newDate(date)
varyear=now.getYear();
varmonth=now.getMonth()+1;
vardate=now.getDate();
varhour=now.getHours();
varminute=now.getMinutes();
varsecond=now.getSeconds();
return"20"+year+"."+month+"."+date;
},
扩展资料
js时间转换(时间戳转date,年月日时分秒)
使用:
1.formatDateTime("时间戳","yyyy-MM-dd")
2.formatDateTime("时间戳","yyyyMMdd")
exportfunctionformatDateTime(time,format){
vart=newDate(time);
vartf=function(i){return(i<10?'0':'')+i};
returnformat.replace(/yyyy|MM|dd|HH|mm|ss/g,function(a){
switch(a){
case'yyyy':
returntf(t.getFullYear());
break;
case'MM':
returntf(t.getMonth()+1);
break;
case'mm':
returntf(t.getMinutes());
break;
case'dd':
returntf(t.getDate());
break;
case'HH':
returntf(t.getHours());
break;
case'ss':
returntf(t.getSeconds());
break;
}
})
}
热心网友 时间:2022-05-14 22:11
当前时间为:<span id="now"></span>
<script type="text/javascript">
//动态显示年月日时间和周几
//显示当前时间的对象ID
//制作:凌陈亮(QQ:57404811)
//来源:http://www.lingchenliang.com/post/45.html
gw_now('now');
function gw_now(id){
var obj=window.document.getElementById(id);
var date=new Date();
var year=date.getFullYear();
var month=gw_now_addzero(date.getMonth()+1);
var day=gw_now_addzero(date.getDate());
var hour=gw_now_addzero(date.getHours());
var minute=gw_now_addzero(date.getMinutes());
var second=gw_now_addzero(date.getSeconds());
switch (date.getDay()) {
case 0:week="星期天";break
case 1:week="星期一";break
case 2:week="星期二";break
case 3:week="星期三";break
case 4:week="星期四";break
case 5:week="星期五";break
case 6:week="星期六";break
}
obj.innerHTML=year + "-" + month + "-" + day + " " + hour + ":" + minute + ":" + second + " " + week;
setTimeout("gw_now('" + id + "')",1000);
}
function gw_now_addzero(temp){
if(temp<10) return "0" + temp;
else return temp;
}
</script>