跳到内容

BTEC IT 20 单元 - 网站设计/JavaScript/自动日期/时间

来自维基教科书,开放的书籍,为开放的世界

显示星期几/日期(例如星期三,2017 年 2 月 1 日)

<head>
<title>My Example</title>
</head>
<body>
  <time id="msg"></time>
<script>
  // Create a JavaScript Date object for the current date and time, and set the desired options.
  var date = new Date(),
      options = { weekday: "long", month: "long", day: "numeric", year: "numeric" };
 
  // Convert to locale string and add a locale and the options
  date = date.toLocaleString( "en-US", options );
 
  // Output the date to the above HTML element
  document.getElementById("msg").innerHTML = date;
</script>
</body>
华夏公益教科书