输出今天日期,以yyyy-mm-dd方式输出

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>时间规格</title>
</head>
<body>
    <script>
      var newDay=new Date();
      var year=newDay.getFullYear();
      var month=newDay.getMonth()+1;
      var day=newDay.getDate();
      month=month<10?"0"+month:month;
      day=day<10?"0"+day:day;
      console.log(year+"-"+month+"-"+day)
    </script>
</body>
</html>

你可能感兴趣的:(js基础面试题,javascript)