跳到內容

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>
華夏公益教科書