今天给大家分享一个js显示当前日期和时间
话不多说,上图:
代码图:
下面是JS代码,可以直接复制使用
<script type="text/javascript">
function time(){
var Week,Week_s,Day;
Week = ["星期天","星期一","星期二","星期三","星期四","星期五","星期六"];
var date = new Date();
year = date.getFullYear();//获取年份
month = date.getMonth() + 1;//获取月份
day = date.getDate();
hours = date.getHours();
minutes = date.getMinutes();
seconds = date.getSeconds();
Week_s = date.getDay();
document.getElementById("time").innerHTML = year + "年"
+ month + "月" + day + "日" + "\t" + hours + ":" + minutes +":" + seconds + "\t" + Week[Week_s] ;
};
setInterval("time()",1000);//每隔1000毫秒会调用一次函数
</script>
如果有更好的办法,欢迎大家在下面评论交流,感谢观看!