主题
js日期对象常用方法
正文
代码加注释,一目了然,直接复制
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script>
var date=new Date();
document.write(date.getYear()); //返回年
date.getMonth();//月
date.getDay();//日
date.getHours();//小时
date.getMinutes();//分钟
date.getSeconds()//秒
document.write(date.toLocaleString()); //返回的是本地日期格式
</script>
</body>
</html>