--- id: php-date title: "PHP Date" category: "Programming_Language" status: "draft" verification_status: "conceptual" canonical_id: "" aliases: ["date()", "strtotime()", "PHP 날짜와 시간"] duplicate_of: "" source_trust_level: "B" confidence_score: 0.9 created_at: 2026-07-04 updated_at: 2026-07-04 review_reason: "" merge_history: [] tags: ["php", "programming", "w3schools", "date", "time"] raw_sources: ["https://www.w3schools.com/php/php_date.asp"] applied_in: [] github_commit: "" --- # [[PHP Date]] ## 🎯 한 줄 통찰 (One-line insight) `strtotime()` accepts natural-language relative expressions like `"+2 weeks 4 days 2 hours 20 seconds"` or `"last Sunday"` and correctly parses them into Unix timestamps — but the source explicitly warns it "is not perfect," meaning arbitrary human phrasing should always be verified rather than trusted blindly. [S1] ## 🧠 핵심 개념 (Core concepts) - **`date(format, timestamp)`** — formats a timestamp (or "now" if omitted) into a readable string. [S1] - **Format characters** — `d`/`j` (day), `m` (month, 2-digit), `Y` (year, 4-digit), `l` (weekday name), `F` (month name), `H`/`h` (24/12-hour), `i` (minutes), `s` (seconds), `a` (am/pm). [S1] - **`date_default_timezone_set()` / `_get()`** — sets/reads the timezone used by all date/time functions in the script. [S1] - **`mktime(hour, minute, second, month, day, year)`** — returns the Unix timestamp for a specific date/time. [S1] - **`time()`** — current time as a Unix timestamp. [S1] - **`strtotime(datetime_string, basetimestamp)`** — parses an English textual date/time description into a Unix timestamp; supports relative expressions. [S1] ## 📖 세부 내용 (Details) - Multiple date formats: `echo date("Y/m/d"); echo date("Y.m.d"); echo date("Y-m-d"); echo date("l"); echo date('l, F j, Y');`. [S1] - Automatic copyright year: `© 2010-`. [S1] - Timezone-aware: `date_default_timezone_set("America/New_York"); echo date("Y-m-d H:i:s");`. [S1] - mktime for a specific historical date: `date_default_timezone_set("UTC"); $d = mktime(0, 0, 0, 10, 3, 1975); echo "October 3, 1975 was on a " . date("l", $d);`. [S1] - Relative date parsing: `$d = strtotime("+2 weeks 4 days 2 hours 20 seconds"); echo date("Y-m-d H:i:s", $d);`. [S1] - Iterative date generation (next 6 Saturdays): `$startdate = strtotime("Saturday"); $enddate = strtotime("+6 weeks", $startdate); while ($startdate < $enddate) { echo date("M d", $startdate) . "
"; $startdate = strtotime("+1 week", $startdate); }`. [S1] ## ⚖️ 모순 및 업데이트 (Contradictions & updates) - **strtotime()의 불완전성 경고**: 자연어 날짜 문자열 파싱이 완벽하지 않으므로 입력 문자열을 항상 검증해야 한다는 팁이 명시됨. [S1] ## 🛠️ 적용 사례 (Applied in summary) 현재 발견된 실제 적용 사례가 없습니다 — 저작권 연도를 date("Y")로 자동 갱신하는 것이 웹사이트 실전 적용의 대표 사례다. [S1] ## 💻 코드 패턴 (Code patterns) Relative date parsing with strtotime() (PHP): ```php $d = strtotime("+2 weeks 4 days 2 hours 20 seconds"); echo "Date is " . date("Y-m-d H:i:s", $d); ``` ## ✅ 검증 상태 및 신뢰도 - **상태:** draft - **검증 단계:** conceptual - **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body) - **신뢰 점수:** 0.90 - **중복 검사 결과:** 신규 생성 (New discovery) ## 🔗 지식 그래프 (Knowledge Graph) - **상위/루트:** [[PHP Tutorial]] - **관련 개념:** [[PHP Form Complete]], [[PHP Includes]] - **참조 맥락:** 날짜/시간 처리 — 파일 포함(Includes) 챕터로 이어짐. ## 📚 출처 (Sources) - [S1] W3Schools — PHP Date and Time — https://www.w3schools.com/php/php_date.asp ## 📝 변경 이력 (Change history) - 2026-07-04: Initial draft synthesized from the W3Schools "PHP Date and Time" page (Astra wiki-curation, P-Reinforce v3.1 format).