--- id: javascript-date-set-methods title: "JavaScript Date Set Methods" category: "Frontend" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["Date setters", "setFullYear", "setMonth", "setDate", "setHours", "setTime", "date comparison"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-06-23 updated_at: 2026-06-23 review_reason: "" merge_history: [] tags: ["javascript", "js", "web", "frontend", "w3schools", "date", "setter"] raw_sources: ["https://www.w3schools.com/js/js_date_methods_set.asp"] applied_in: [] github_commit: "" --- # [[JavaScript Date Set Methods]] ## 🎯 ν•œ 쀄 톡찰 (One-line insight) Date Set methods write a part of a `Date` object β€” year, month, day, hour, minute, second, millisecond, or the raw timestamp β€” and several accept cascading parameters so multiple parts can be set in one call. [S1] ## 🧠 핡심 κ°œλ… (Core concepts) - **Set Date methods set a part of a date.** [S1] - **Months count from 0 to 11** β€” January is 0, December is 11. [S1] - **Cascading parameters** β€” `setFullYear()` can also take month and day; `setHours()` can also take minutes and seconds, letting you set several fields at once. [S1] - **Arithmetic via get + set** β€” combine a getter with a setter (`d.setDate(d.getDate() + 50)`) to shift a date; boundary crossings into the next month/year adjust automatically. [S1] - **Dates are comparable** β€” relational operators (`>`, `<`) compare two `Date` objects directly. [S1] ## 🧩 μΆ”μΆœλœ νŒ¨ν„΄ (Extracted patterns) - **Add-to-existing-field** β€” read a field, add to it, set it back: `d.setDate(d.getDate() + 50)`. [S1] - **Build a target date then compare** β€” create a date, set its fields to a future point, then test with `if (someday > today)`. [S1] - **One-call multi-field set** β€” pass extra arguments to a single setter instead of calling several setters. [S1] ## πŸ“– μ„ΈλΆ€ λ‚΄μš© (Details) **setFullYear() β€” set the year (yyyy)** [S1] ```javascript const d = new Date("January 01, 2025"); d.setFullYear(2020); ``` `setFullYear()` can optionally set the month and day as well: [S1] ```javascript const d = new Date("January 01, 2025"); d.setFullYear(2020, 11, 3); ``` **setMonth() β€” set the month (0-11)** [S1] ```javascript const d = new Date("January 01, 2025"); d.setMonth(11); ``` **setDate() β€” set the day as a number (1-31)** [S1] ```javascript const d = new Date("January 01, 2025"); d.setDate(15); ``` `setDate()` can also be used to add days to a date: [S1] ```javascript const d = new Date("January 01, 2025"); d.setDate(d.getDate() + 50); ``` **setHours() β€” set the hour (0-23)** [S1] ```javascript const d = new Date("January 01, 2025"); d.setHours(22); ``` `setHours()` can also set minutes and seconds: [S1] ```javascript const d = new Date("January 01, 2025"); d.setHours(22, 10, 20); ``` **setMinutes() β€” set the minutes (0-59)** [S1] ```javascript const d = new Date("January 01, 2025"); d.setMinutes(30); ``` **setSeconds() β€” set the seconds (0-59)** [S1] ```javascript const d = new Date("January 01, 2025"); d.setSeconds(30); ``` **Compare Dates** β€” dates can easily be compared. The example sets a future date and compares it to today: [S1] ```javascript let text = ""; const today = new Date(); const someday = new Date(); someday.setFullYear(2100, 0, 14); if (someday > today) { text = "Today is before January 14, 2100."; } else { text = "Today is after January 14, 2100."; } ``` **Set Date Methods** [S1] | Method | Description | |--------|-------------| | setDate() | Set the day as a number (1-31) | | setFullYear() | Set the year (yyyy) | | setHours() | Set the hour (0-23) | | setMilliseconds() | Set the milliseconds (0-999) | | setMinutes() | Set the minutes (0-59) | | setMonth() | Set the month (0-11) | | setSeconds() | Set the seconds (0-59) | | setTime() | Set the time (milliseconds since January 1, 1970) | **Note:** JavaScript counts months from 0 to 11. January is 0. December is 11. [S1] ## πŸ› οΈ 적용 사둀 (Applied in summary) The page's own snippets are the canonical applied examples β€” setting individual fields on a parsed date, adding 50 days via `setDate(d.getDate() + 50)`, and building a future date to compare against today. No external project/commit applications found in the source. ## πŸ’» μ½”λ“œ νŒ¨ν„΄ (Code patterns) Shift a date forward by N days (language: JavaScript): ```javascript const d = new Date("January 01, 2025"); d.setDate(d.getDate() + 50); ``` Set multiple fields in one call: ```javascript const d = new Date("January 01, 2025"); d.setHours(22, 10, 20); ``` ## βš–οΈ λͺ¨μˆœ 및 μ—…λ°μ΄νŠΈ (Contradictions & updates) No contradictions found in the source. ## βœ… 검증 μƒνƒœ 및 신뒰도 - **μƒνƒœ:** draft - **검증 단계:** conceptual (μ‹€μ œ 적용 사둀 발견 μ‹œ applied/validated둜 승격 κ°€λŠ₯) - **좜처 신뒰도:** B (W3Schools β€” widely used educational reference, not a primary standards body) - **μ‹ λ’° 점수:** 0.90 - **쀑볡 검사 κ²°κ³Ό:** μ‹ κ·œ 생성 (New discovery) ## πŸ”— 지식 κ·Έλž˜ν”„ (Knowledge Graph) - **μƒμœ„/루트:** [[JavaScript Tutorial]] - **κ΄€λ ¨ κ°œλ…:** [[JavaScript Date Get Methods]], [[JavaScript Date Methods]], [[JavaScript Dates]] - **μ°Έμ‘° λ§₯락:** Used whenever mutating a Date object β€” adjusting fields, doing date arithmetic, or building target dates for comparison. ## πŸ“š 좜처 (Sources) - [S1] W3Schools β€” JavaScript Date Set Methods β€” https://www.w3schools.com/js/js_date_methods_set.asp ## πŸ“ λ³€κ²½ 이λ ₯ (Change history) - 2026-06-23: Initial draft synthesized from the W3Schools "JavaScript Date Set Methods" page (Astra wiki-curation, P-Reinforce v3.1 format).