JS之Date函数获取时间代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JS之Date函数获取时间代码</title>
</head>
<body>
<script>
function check(x){
if(x<10){
return '0'+x;
}
return x;
}
var time = new Date();
var year = time.getFullYear();
var month = time.getMonth()+1;
var day = time.getDay();
var hour = check(time.getHours());
var minute = check(time.getMinutes());
var second = check(time.getSeconds());
console.log(year+'-'+month+'-'+day+' '+hour+':'+minute+':'+second);
</script>
</body>
</html>