进攻参考,其中,注意获取当前月份要就加1,因为getDate方法从 Date 对象返回月份是 0 ~ 11,因此要想获取1~12月份,需要加1。
<html>
<head>
<title>日期练习</title>
</head>
<body>
<script type="text/javascript">
var curtime = new Date();
var year = curtime.getYear();
var month = curtime.getMonth() + 1;
var day = curtime.getDate();
var hours = curtime.getHours();
var minutes = curtime.getMinutes();
var seconds = curtime.getSeconds();
document.write("此时的时间是"+year+"年"+month+"月"+day+"日"+hours+"时"+minutes+"分"+seconds+"秒");
</script>
</body>
</html>