답변 3개
채택된 답변
+20 포인트
3개월 전
이렇게 하면 간단하게 됩니다
$originalDate = "2025-08-18";
echo $final = date("Y-m-d", strtotime("$originalDate +1 month"));
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
3개월 전
</p>
<p><!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>날짜 계산기</title>
<style>
body {
font-family: 'Segoe UI', sans-serif;
background: #f3f4f6;
padding: 30px;
text-align: center;
}
h1 {
color: #333;
}
input[type="date"] {
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 8px;
}
button {
margin-top: 15px;
padding: 10px 20px;
font-size: 16px;
background-color: #4f46e5;
color: white;
border: none;
border-radius: 8px;
cursor: pointer;
transition: background-color 0.3s ease;
}
button:hover {
background-color: #4338ca;
}
.result {
margin-top: 30px;
background: white;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0,0,0,0.1);
display: inline-block;
text-align: left;
}
.result div {
margin: 8px 0;
}
</style>
</head>
<body></p>
<p> <h1>? 날짜 계산기</h1>
<p>기준 날짜를 선택하세요:</p>
<input type="date" id="baseDate" />
<button onclick="calculateDates()">날짜 계산하기</button></p>
<p> <div class="result" id="resultBox" style="display:none;"></div></p>
<p> <script>
function calculateDates() {
const base = document.getElementById('baseDate').value;
if (!base) return alert("날짜를 선택해주세요!");</p>
<p> const baseDate = new Date(base);
const resultBox = document.getElementById("resultBox");
const weekdays = ['일', '월', '화', '수', '목', '금', '토'];</p>
<p> const addDate = (d, days = 0, months = 0, years = 0) => {
const newDate = new Date(d);
newDate.setDate(newDate.getDate() + days);
newDate.setMonth(newDate.getMonth() + months);
newDate.setFullYear(newDate.getFullYear() + years);
return newDate;
}</p>
<p> const format = (d) =>
`${d.getFullYear()}-${(d.getMonth() + 1).toString().padStart(2, '0')}-${d.getDate().toString().padStart(2, '0')} (${weekdays[d.getDay()]})`;</p>
<p> const results = [
{ label: '7일 후', date: addDate(baseDate, 7) },
{ label: '보름 후 (15일)', date: addDate(baseDate, 15) },
{ label: '1개월 후', date: addDate(baseDate, 0, 1) },
{ label: '3개월 후', date: addDate(baseDate, 0, 3) },
{ label: '6개월 후', date: addDate(baseDate, 0, 6) },
{ label: '1년 후', date: addDate(baseDate, 0, 0, 1) },
{ label: '2년 후', date: addDate(baseDate, 0, 0, 2) }
];</p>
<p> resultBox.innerHTML = `<strong>? 기준일: ${format(baseDate)}</strong>
<hr>`;
results.forEach(item => {
resultBox.innerHTML += `<div>? ${item.label}: <strong>${format(item.date)}</strong></div>`;
});
resultBox.style.display = 'block';
}
</script></p>
<p></body>
</html></p>
<p>
로그인 후 평가할 수 있습니다
댓글을 작성하려면 로그인이 필요합니다.
답변을 작성하려면 로그인이 필요합니다.
로그인