【2】JS输出日期

3 篇文章 0 订阅
<!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():输出信息

-->


得到时间方法:
  getDate() 查看Date对象并返回日期
  getDay() 返回星期几
  getHours() 返回小时数
  getMinutes() 返回分钟数
  getMonth() 返回月份值
  getSeconds() 返回秒数
  getTime() 返回完整的时间
  getYear() 返回年份
设置时间方法:
  setDate() 改变Date对象的日期
  setHours() 改变小时数
  setMinutes() 改变分钟数
  setMonth() 改变月份
  setSeconds() 改变秒数
  setTime() 改变完整的时间
  setYear() 改变年份

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值