new Date()时间对象

108 阅读1分钟
<script>
  // console.log(new Date()); /* 年月日星期几几点 */
  // console.log(new Date(2022, 0, 1)); /*哪年哪月哪日星期几的几点 */
  //  // 得到一个当前时间对象
  var date = new Date(); /* 这里的date是一个对象 */
  // 既然是对象就可以操作对象的属性
  // 获取年月日时分秒 记得加括号
  console.log(date.getDate());
  console.log(date.getDay());
  console.log(date.getMonth());
  console.log(date.getFullYear());
</script>