Get to know MDN better
此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
Date 實例的 setUTCHours() 方法會根據世界協調時間變更此日期的時、分、秒及/或毫秒。
一個介於 0 到 23 之間的整數,表示小時。
minutesValue 選擇性一個介於 0 到 59 之間的整數,表示分鐘。
secondsValue 選擇性一個介於 0 到 59 之間的整數,表示秒。若你指定 secondsValue,則必須同時指定 minutesValue。
msValue 選擇性一個介於 0 到 999 之間的整數,表示毫秒。若你指定 msValue,則必須同時指定 minutesValue 和 secondsValue。
就地更改 Date 物件,並回傳其新的時間戳。若參數為 NaN(或其他會被強制轉型為 NaN 的值,例如 undefined),則日期會被設為無效日期,並回傳 NaN。
若你沒有指定 minutesValue、secondsValue 和 msValue 參數,將會使用 getUTCMinutes()、getUTCSeconds() 和 getUTCMilliseconds() 方法回傳的值。
若你指定的參數超出預期範圍,setUTCHours() 會相應地嘗試更新 Date 物件中的日期訊息。例如,若你為 secondsValue 指定 100,則分鐘數會增加 1(minutesValue + 1),而秒數則會使用 40。
| ECMAScript® 2027 Language Specification # sec-date.prototype.setutchours |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025年8月19日 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.