效果图:
<img src="https://img.php.cn/upload/article/000/023/547/7791f6c3ce06e2e31c49919fd4266443-0.jpg" alt=""><br>
<!--代码展示-->
<html>
<head>
<metahttp-equiv="Content-Type"content="text/html; charset=gb2312"/>
<title>无标题文档</title>
<scripttype="text/javascript">
//定义函数:构建要显示的时间日期字符串
function showTime()
{
//创建Date对象
var today = new Date();
//分别取出年、月、日、时、分、秒
var year = today.getFullYear();
var month = today.getMonth()+1;
var day = today.getDate();
var hours = today.getHours();
var minutes = today.getMinutes();
var seconds = today.getSeconds();
//如果是单个数,则前面补0
month = month<10 ? "0"+month : month;
day = day <10 ? "0"+day : day;
hours = hours<10 ? "0"+hours : hours;
minutes= minutes<10 ? "0"+minutes : minutes;
seconds= seconds<10 ? "0"+seconds : seconds;
//构建要输出的字符串
varstr = year+"年"+month+"月"+day+"日 "+hours+":"+minutes+":"+seconds;
//获取id=result的对象
varobj = document.getElementById("result");
//将str的内容写入到id=result的<p>中去
obj.innerHTML = str;
//延时器
window.setTimeout("showTime()",1000);
}
</script>
<styletype="text/css">
#result{
width:500px;
border:1px solid #CCCCCC;
background:#FFFFCC;
margin:50px auto;
font-size:24px;
color:#FF0000;
padding:20px;
}
</style>
</head>
<bodyonload="showTime()">
<pid="result"></p>
</body>
</html>以上就是用js显示当前系统时间的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号