Date.prototype.setTime()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since â¨2015ë 7ìâ©.
setTime() ë©ìëë Date ê°ì²´ë¥¼ 1970ë
1ì 1ì¼ 00:00:00 UTCë¶í°
ë°ë¦¬ ì´ ë¨ìë¡ ëíë´ë ìê°ì¼ë¡ ì¤ì í©ëë¤.
ìëí´ ë³´ê¸°
const launchDate = new Date("July 1, 1999, 12:00:00");
const futureDate = new Date();
futureDate.setTime(launchDate.getTime());
console.log(futureDate);
// Expected output: "Thu Jul 01 1999 12:00:00 GMT+0200 (CEST)"
const fiveMinutesInMillis = 5 * 60 * 1000;
futureDate.setTime(futureDate.getTime() + fiveMinutesInMillis);
console.log(futureDate);
// Expected output: "Thu Jul 01 1999 12:05:00 GMT+0200 (CEST)"
// Note: your timezone may vary
구문
js
setTime(timeValue)
매ê°ë³ì
timeValue-
1970ë 1ì 1ì¼ 00:00:00 UTC ì´íì ë°ë¦¬ ì´ ì를 ëíë´ë ì ì ê° ì ëë¤.
ë°í ê°
1970ë 1ì 1ì¼ 00:00:00 UTCì ì ë°ì´í¸ ë ë ì§ (ì¬ì¤ì ì¸ìì ê°) ì¬ì´ì ë°ë¦¬ ì´ ìì ëë¤.
ì¤ëª
setTime() ë©ìë를 ì¬ì©íë©´ ë¤ë¥¸ Date ê°ì²´ì ë ì§ì ìê°ì ì§ì í ì ììµëë¤.
ìì
>setTime() ì¬ì©í기
js
const theBigDay = new Date("July 1, 1999");
const sameAsBigDay = new Date();
sameAsBigDay.setTime(theBigDay.getTime());
ëª ì¸ì
| Specification |
|---|
| ECMAScript® 2026 Language Specification > # sec-date.prototype.settime > |