docs(10_Wiki): W3Schools 위키화 — HTML/CSS/JavaScript(core)
W3Schools 튜토리얼을 P-Reinforce v3.1 포맷으로 위키화(영어 본문, 한/영 섹션 헤더). - Topic_HTML: 59문서 (튜토리얼+예제, 레퍼런스/메타 제외) - Topic_CSS: 190문서 (메인 + Advanced/Flexbox/Grid/RWD 전체) - Topic_JavaScript: 120문서 (코어 언어; Temporal/DOM상세/BOM/WebAPI/AJAX/jQuery/Graphics 등은 후속) 각 폴더 00_INDEX.md(MOC) 포함. 코드 verbatim, 미확인분은 "Not found in source" 표기. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,154 @@
|
||||
---
|
||||
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).
|
||||
Reference in New Issue
Block a user