需要用到的记录下,主要使用js中setTimeout延迟每一秒获取当前时间
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>test jquer orgs</title>
<script type="text/javascript" src="jquery.min.js"></script>
</head>
<body>
<div id="realtime"></div>
<script>
$(function () {
CurrentTime();
})
function CurrentTime() {
var date = new Date();
var year = date.getFullYear();
var month = date.getMonth() + 1;
var day = date.getDate();
var hour = date.getHours();
var minute = date.getMinutes();
var second = date.getSeconds();
month = month < 10 ? ("0" + month) : month;
day = day < 10 ? ("0" + day) : day;
hour = hour < 10 ? ("0" + hour) : hour;
minute = minute < 10 ? ("0" + minute) : minute;
second = second < 10 ? ("0" + second) : second;
var Timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second;
//在页面上插入日期
$("#realtime").html(Timer);
setTimeout(function () {
CurrentTime();
}, 1000);
}
</script>
</body>
</html>内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://sulao.cn/post/768
评论列表