datetime2.js

来自「人力资源管理系统」· JavaScript 代码 · 共 32 行

JS
32
字号
var timerID = null;
var timerRunning = false;

function stopclock (){
	if(timerRunning)
		clearTimeout(timerID);
	timerRunning = false;
}
function startclock () {
	stopclock();
	showtime();
}
function showtime () {
	var now = new Date();
	var hours = now.getHours();
	var minutes = now.getMinutes();
	var seconds = now.getSeconds();
	var timeValue = now.getFullYear()+"-";
	timeValue += (now.getMonth()+1)+"-";
	timeValue += now.getDate()+" ";
	timeValue += hours;

	timeValue += ((minutes < 10) ? ":0" : ":") + minutes;
	timeValue += ((seconds < 10) ? ":0" : ":") + seconds;

	document.getElementById("currentTime").value=timeValue;
	
	timerID = setTimeout("showtime()",1000);
	timerRunning = true;
}
window.onload=startclock;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?