Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> JavaScript

Thiết lập năm đầy đủ cho Date theo UTC

Phương thức setUTCFullYear() thiết lập năm (và tùy chọn tháng, ngày) cho Date theo UTC.

Tham số:

  • yearValue – Năm đầy đủ (vd 2018).
  • monthValue (tùy chọn) – 0-11.
  • dayValue (tùy chọn) – 1-31, bắt buộc có monthValue.

Ví dụ

<html>
  <head>
    <title>JavaScript setUTCFullYear Method</title>
  </head>
  <body>
    <script>
      var dt = new Date("Aug 28, 2012 23:30:00");
      dt.setUTCFullYear(2018);
      document.write(dt);
    </script>
  </body>
</html>