js
CHAPTER 32 / 34
읽기 약 2분
FUNCTION
날짜와 시간: Date 객체
핵심 개념
Date 객체로 날짜/시간을 생성하고 조작합니다. Date.now()는 Unix 타임스탬프(ms), new Date()는 현재 시간입니다. getFullYear(), getMonth()(0부터), getDate(), getHours() 등으로 컴포넌트를 추출합니다. toLocaleDateString(), toISOString()으로 포맷팅합니다. Intl.DateTimeFormat으로 국제화된 날짜 형식을 표현합니다.
코드 분석
const now = new Date();
const timestamp = Date.now();
const year2029 = new Date('2029-07-25');
const diff = year2029 - now;
const daysUntil = Math.floor(diff / (1000 * 60 * 60 * 24));
const formatted = new Intl.DateTimeFormat('ko-KR', {
year: 'numeric', month: 'long', day: 'numeric',
hour: '2-digit', minute: '2-digit'
}).format(now);
document.write('<div style="color:#10b981;margin-bottom:4px;">현재: ' + now.toISOString() + '</div>');
document.write('<div style="color:#f59e0b;margin-bottom:4px;">타임스탬프: ' + timestamp + '</div>');
document.write('<div style="color:#22c55e;margin-bottom:4px;">심판의 날(2029-07-25)까지: ' + daysUntil + '일</div>');
document.write('<div style="color:#888;margin-bottom:4px;">한국어 포맷: ' + formatted + '</div>');
document.write('<div style="color:#888;">월(0-based): ' + now.getMonth() + ' (실제 ' + (now.getMonth()+1) + '월)</div>');AI 프롬프트
🤖 AI에게 잘 물어보는 법 — 모델·전략별 프롬프트
Claude
무료: Sonnet 4.6 / Pro $20/mo: Opus 4.6
이 JS '날짜와 시간' 코드의 잠재적 버그와 메모리 누수·this 바인딩·비동기 경합 위험을 분석해서 프로덕션 수준으로 개선해줘.
ChatGPT
무료: GPT-5.5 / Plus $20/mo: GPT-5.5 Pro
'날짜와 시간'를 실제 서비스에서 어떻게 쓰는지 구체적 사례 3개와 복사 가능한 코드를 초보자가 이해할 수 있게 보여줘.
Gemini
무료: 2.5 Flash / Pro $19.99/mo: 3.1 Pro
이 JS '날짜와 시간' 관련 코드 전체의 실행 흐름을 분석하고 성능 병목과 최적화 방안을 우선순위로 알려줘.
Grok
무료: Grok 4.1 / SuperGrok $30/mo
'날짜와 시간'에서 개발자들이 가장 많이 하는 실수 Top 3을 솔직하게 알려주고 2026년 권장 패턴을 함께 알려줘.
⭐ 이것만 기억하세요
날짜와 시간: Date 객체는 이 3가지만 확실히 잡으세요
1.Date 객체의 월(month)이 0부터 시작하는 것을 모르면 1월을 넣었는데 2월이 나오는 버그가 발생합니다
2.new Date()로 현재 시간, getTime()으로 타임스탬프, toISOString()으로 국제 표준 형식을 얻습니다
3.다음 챕터에서 요소가 화면에 보이는지 감지하는 IntersectionObserver를 배웁니다
공유하기
진행도 32 / 34