时钟显示 html JavaScript

sf.html

html 复制代码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>时间</title>
		<script>
			function showTime()
			{
				var time=new Date();
				
				var date=time.getDate();
				var year=time.getFullYear();
				var month=time.getMonth()+1;
				var hour=time.getHours();
				var minute=time.getMinutes();
				var second=time.getSeconds();
				var nianyueri=year+"年"+"&nbsp"+month+"月"+"&nbsp"+date+"日";
				var mytime=hour+":"+minute+":"+second;
				
				document.getElementById("nianyueri").innerHTML=nianyueri;
				document.getElementById("sj").innerHTML=mytime;
				setTimeout("showTime()",1000);
			}
		</script>
	</head>
	<body>
		<div>
			<div id="nianyueri"></div>
			<div id="sj">20:57</div>
			<script>
				showTime();
			</script>
		</div>
	</body>
</html>

运行后

单独显示年份

year.html

html 复制代码
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>年</title>
		<script>
			function showTime()
			{
				var time=new Date();
				var year=time.getFullYear();
				var showyear=year+'年';
				
				document.getElementById("Year").innerHTML=showyear;
				
				
			}
		</script>
	</head>
	<body>
		<div id="Year"></div>
		<script>showTime()</script>
	</body>
</html>
相关推荐
勇往直前plus9 分钟前
Vue3(篇四)单页面应用到路由管理
javascript·typescript·前端框架·vue
Chengbei111 小时前
云安全漏洞挖掘SKILL、一站式云漏洞挖掘工具,支持S3爆破、IMDS探测、K8s检测与AK/SK权限利用
前端·人工智能·网络安全·云原生·容器·kubernetes·系统安全
不简说2 小时前
JS 代码技巧 vol.9 — 20 个设计模式在真实项目里的应用
前端·javascript·github
CoderLiu2 小时前
Agent 工程的下一层:为什么「把流程写成图」还不够,还需要 Graph Engineering
前端·人工智能·后端
勇往直前plus2 小时前
Vue3(篇三) Element Plus
前端·javascript·typescript·vue
爱勇宝2 小时前
《道德经》第 8 章:真正高级的能力,像水一样成事
前端·后端·程序员
Revolution612 小时前
数组本身没有 map,为什么还能直接调用:原型链怎样查找属性
前端·javascript·面试
bonechips2 小时前
RAG实战(一):EPUB 加载、文本切割与向量入库
前端·数据库
swipe2 小时前
10|(前端转全栈)库存扣减为什么最容易出事故?SKU、并发与原子更新
前端·后端·全栈
cdcdhj2 小时前
vue3中的watchEffect()监听,什么时候监听,什么时候清理,什么时候停止
前端·javascript·vue.js