<!DOCTYPE html>
<html>
<head>
	<title>时间戳转换工具</title>
	<script>
		function showTimestamp() {
			var timestamp = Math.floor(Date.now() / 1000);
			document.getElementById("timestamp").innerHTML = timestamp;
			setTimeout(showTimestamp, 1000);
		}
<pre><code>	function formatTimestamp() {
		var input = document.getElementById(&quot;input&quot;).value;
		var output = new Date(input * 1000).toLocaleString();
		document.getElementById(&quot;output&quot;).innerHTML = output;
	}

	function convertToTimestamp() {
		var input = document.getElementById(&quot;input&quot;).value;
		var output = Math.floor(Date.parse(input) / 1000);
		document.getElementById(&quot;output&quot;).innerHTML = output;
	}
&lt;/script&gt;
</code></pre>
</head>
<body onload="showTimestamp()">
	<h1>时间戳转换工具</h1>
	<p>当前时间戳:<span id="timestamp"></span></p>
	<hr>
	<h3>格式化时间戳</h3>
	<p>输入时间戳:<input type="text" id="input"></p>
	<button onclick="formatTimestamp()">格式化</button>
	<p>格式化结果:<span id="output"></span></p>
	<hr>
	<h3>转换为时间戳</h3>
	<p>输入时间:<input type="text" id="input"></p>
	<button onclick="convertToTimestamp()">转换</button>
	<p>转换结果:<span id="output"></span></p>
</body>
</html>
帮我写一个html功能1显示当前时间戳且按秒实时变动。功能2通过输入时间戳格式化输出功能3输入时间转成时间戳输出

原文地址: https://www.cveoy.top/t/topic/blqZ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录