<!DOCTYPE html > <!--写html的声明(文档类型声明-->
<html> <!--表示html类型文档开始-->
<head> <!--文档元素数据开始(不可见)-->
<meta charset="utf-8"> <!--声明字体的格式(防止中文不能显示)-->
<title>测试成功</title> <!--设置文档的标题-->
</head>
<body> <!--在这里设置网页的主内容-->
<script type="text/javascript">
var cur = new Date();
document.write(cur + "<br>")
document.write("此处时间是:" + cur.getYear() + "年" + cur.getMonth() + "月" + cur.getDate() + "日"
+ cur.getHours() + "时" + cur.getMinutes() + "分" + cur.getSeconds() + "秒" + "<br>");
cur.setYear(2019);
cur.setMonth(09);
cur.setDate(09);
cur.setHours(09);
cur.setMinutes(09);
cur.setSeconds(09);
document.write("此处时间是:" + cur.getYear() + "年" + cur.getMonth() + "月" + cur.getDate() + "日"
+ cur.getHours() + "时" + cur.getMinutes() + "分" + cur.getSeconds() + "秒" + "<br>");
</script>
</body>
</html>
<!--
var cur = new Date(); Var:数据类型 cur获取现在的日期
cur.getYear():获取该日期中的年
cur.setYear(2019):重置该日期中的年
document.write():输出信息
-->
<html> <!--表示html类型文档开始-->
<head> <!--文档元素数据开始(不可见)-->
<meta charset="utf-8"> <!--声明字体的格式(防止中文不能显示)-->
<title>测试成功</title> <!--设置文档的标题-->
</head>
<body> <!--在这里设置网页的主内容-->
<script type="text/javascript">
var cur = new Date();
document.write(cur + "<br>")
document.write("此处时间是:" + cur.getYear() + "年" + cur.getMonth() + "月" + cur.getDate() + "日"
+ cur.getHours() + "时" + cur.getMinutes() + "分" + cur.getSeconds() + "秒" + "<br>");
cur.setYear(2019);
cur.setMonth(09);
cur.setDate(09);
cur.setHours(09);
cur.setMinutes(09);
cur.setSeconds(09);
document.write("此处时间是:" + cur.getYear() + "年" + cur.getMonth() + "月" + cur.getDate() + "日"
+ cur.getHours() + "时" + cur.getMinutes() + "分" + cur.getSeconds() + "秒" + "<br>");
</script>
</body>
</html>
<!--
var cur = new Date(); Var:数据类型 cur获取现在的日期
cur.getYear():获取该日期中的年
cur.setYear(2019):重置该日期中的年
document.write():输出信息
-->
得到时间方法:
getDate() 查看Date对象并返回日期
getDay() 返回星期几
getHours() 返回小时数
getMinutes() 返回分钟数
getMonth() 返回月份值
getSeconds() 返回秒数
getTime() 返回完整的时间
getYear() 返回年份
设置时间方法:
setDate() 改变Date对象的日期
setHours() 改变小时数
setMinutes() 改变分钟数
setMonth() 改变月份
setSeconds() 改变秒数
setTime() 改变完整的时间
setYear() 改变年份