程序员python 高级码农成才之路

javascript----windows自带的时间函数

2020-12-05  本文已影响0人  幼姿沫

<!DOCTYPE html>

<html>

<head>

<meta charset="utf-8">

<title>window自带属性</title>

</head>

<body>

<button id='btn1' onclick='window.close()'>关闭窗口</button>

<h1>时间*<span id='mytime'></span></h1>

<script type='text/javascript'>

/* window系统自带的时间间隔  setTimeout只是调用一次  setInterval循环调用*/

window.setTimeout('fn1()',3000);

window.setInterval('fn2()',3000);

function fn1(){

console.log('3秒之后调用一次')

}

function fn2(){

console.log('每每经过3秒调用一次')

}

/* 每隔1秒进行时间的更新 */

setInterval('showtime()',1000);

function showtime(){

var time=new Date()

var mytime=document.getElementById('mytime')

//获取时间的年月日时分秒

var year=time.getFullYear();

var month=time.getMonth();

var day=time.getDate();

var hour=time.getHours();

var mintinue=time.getMinutes();

var seconds=time.getSeconds();

if(month<10 ){

month='0'+month;

}

if(day<10){

day='0'+day;

}

if(hour<10){

hour='0'+hour;

}

if(mintinue<10){

mintinue='0'+mintinue;

}

if(seconds<10){

seconds='0'+seconds;

}

var t=year+'-'+month+'-'+day+' '+hour+':'+mintinue+':'+seconds

mytime.innerHTML=t;

}

</script>

</body>

</html>

上一篇 下一篇

猜你喜欢

热点阅读