JS中使用Date对象实时显示系统时间小示例

来源:互联网 发布:dnf经常网络中断2017 编辑:程序博客网 时间:2024/04/29 13:35

JS中包含Date对象,其提供了一些方法获取系统日期,直接上代码:

<!DOCTYPE html><html><head><meta charset="utf-8" /><title>获取系统时间</title><script language="JavaScript">function realSysTime(clock) {var now = new Date();var year = now.getFullYear(); //获取年份var month = now.getMonth(); //获取月份var date = now.getDate(); //获取日期var day = now.getDay(); //获取星期var hour = now.getHours(); //获取小时var minute = now.getMinutes(); //获取分钟var seconds = now.getSeconds(); //获取秒month = month + 1;var arr_week = new Array("星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六");var week = arr_week[day];var time = year + "年" + month + "月" + date + "日 " + week + " " + hour + ":" + minute + ":" + seconds;clock.innerHTML = "当前时间:" + time;}function show() {window.setInterval("realSysTime(clock)", 1000);}</script></head><body onload="show()" wind><div id='clock'></div></body></html>


0 0
原创粉丝点击