나는보고 대답을 찾지 못했습니다.PHP 달력이 건너 뜁니다.
나는 php 달력을 가지고 있으며 다음 달 또는 지난 달에 feb로 이동하면 feb를 건너 뛰고 feb는 건너 뛰고 feb는 skb로 이동합니다. 4 년마다이 작업을 수행하므로 윤년과 관련이 있지만 문제를 발견하지 못하는 것 같습니다.
<html>
<head>
<script>
function goLastMonth(month, year){
if (month == 1) {
--year;
month = 13;
}
document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+(month-1)+"&year="+year;
}
function goNextMonth(month, year){
if (month == 12) {
++year;
month = 0;
}
document.location.href = "<?php $_SERVER['PHP_SELF'];?>?month="+(month+1)+"&year="+year;
}
</script>
</head>
<body>
<?php
if (isset($_GET['day'])){
$day = $_GET['day'];
}else{
$day = date("j");
}
if (isset($_GET['month'])){
$month = $_GET['month'];
}else{
$month = date("n");
}
if (isset($_GET['year'])){
$year = $_GET['year'];
}else{
$year = date("Y");
}
// calender variable //
$currentTimeStamp = strtotime("$year-$month-$day");
$monthName = date("F", $currentTimeStamp);
$numDays = date("t", $currentTimeStamp);
$counter = 0;
?>
<table border='1'>
<tr>
<td><input style='width:50px;' type='button' value='<' name='previousbutton' onclick="goLastMonth(<?php echo $month.",".$year?>)"></td>
<td colspan='5' align='center'> <?php echo $monthName.", ".$year; ?></td>
<td><input style='width:50px;' type='button' value='>' name='nextbutton' onclick="goNextMonth(<?php echo $month.",".$year?>)"></td>
<td></td>
</tr>
<tr>
<td width='50px' align='center'>D</td>
<td width='50px' align='center'>L</td>
<td width='50px' align='center'>M</td>
<td width='50px' align='center'>M</td>
<td width='50px' align='center'>J</td>
<td width='50px' align='center'>V</td>
<td width='50px' align='center'>S</td>
</tr>
<?php
echo "<tr>";
for($i = 1; $i < $numDays+1; $i++, $counter++) {
$timeStamp = strtotime("$year-$month-$i");
if ($i == 1) {
$firstDay = date("w", $timeStamp);
for ($j = 0; $j < $firstDay; $j++, $counter++) {
// blank space //
echo "<td> </td>";
}
}
if ($counter % 7 == 0 && $counter != 0){
echo "</tr><tr>";
}
echo "<td align='center'>".$i."</td>";
}
echo "</tr>";
?>
</table>
</body>
당신의'goLastMonth'와'goNextMonth'는 꽤 생생 해 보입니다. 왜 당신은 돌아갈 때 "1 월 1 일"에서 "13 월"으로 갈 것이지만 앞으로 갈 때 "12 월"에서 "0 월"으로 갈 것입니다. – meagar
DateTime 객체를 살펴 보시지 않겠습니까? http://php.net/manual/en/datetime.add.php –