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

Thiết lập giờ cho Date theo UTC

Phương thức setUTCHours() thiết lập giờ (và tùy chọn phút, giây, mili-giây) cho Date theo UTC.

Tham số:

  • hoursValue – 0-23.
  • minutesValue (tùy chọn) – 0-59.
  • secondsValue (tùy chọn) – 0-59.
  • msValue (tùy chọn) – 0-999.

Ví dụ

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