프로그래머가 되고 나서 처음으로 달력을 짜보았습니다.
그동안 일하면서 어떻게 달력이 필요 한 작업이 하나도 없었을까요??? 아이러니 하네요 ㅎㅎㅎ
방금 하나 만들어 봤는데 유효한지 모르겠네요~
[code]
/*
* "년, 월, 일"의 초기 값을 설정한다.(전달값이 있을경우 전달값 출력)
*/
$Year = ($_REQUEST['year'])?$_REQUEST['year']:date('Y');
$Month = ($_REQUEST['month'])?str_pad($_REQUEST['month'], 2, 0, STR_PAD_LEFT):date('m');
$Day = ($REQUEST['day'])?str_pad($_REQUEST['day'], 2, 0, STR_PAD_LEFT):date('d');
/*
* 초기 조건값
*/
$FirstDayWeek = date('w', strtotime($Year.$Month.'01')); // 1일은 몇 요일?
$LastDay = date('t', strtotime($Year.$Month.'01')); // 몇일까지 있니?
$PreLastDay = date('t', strtotime("-1 month", strtotime($Year.$Month.'01'))); // 지난달은 몇일 까지 있니?
$Day = $PreLastDay - $FirstDayWeek;
$HiddenDate = true;
?>
<div class="reservation">
<table class="calendar">
<thead>
<tr class="week">
<th scope="col">일요일</th>
<th scope="col">월요일</th>
<th scope="col">화요일</th>
<th scope="col">수요일</th>
<th scope="col">목요일</th>
<th scope="col">금요일</th>
<th scope="col">토요일</th>
</tr>
</thead>
<tbody class="mon">
<?php for($m=1; $m<7; $m++) { ?>
<tr>
<?php
for($w=0; $w<7; $w++) {
if($Day >= $PreLastDay) {
$HiddenDate = false;
$Day = 0;
$PreLastDay = $LastDay;
$FullDate = '';
}
$Day++; // day 증가
$FullDate = $Year.'-'.str_pad($Month, 2, 0, STR_PAD_LEFT).'-'.str_pad($Day, 2, 0, STR_PAD_LEFT);
if($HiddenDate || date('w', strtotime($FullDate)) <> $w) {
$FullDate = '';
$HiddenDate = true;
}
?>
<td>
<div><strong>날짜:</strong> <?php echo $Day; ?></div>
<div><strong>년.월.일:</strong> <?php echo ($FullDate)?$FullDate:'해당없음'; ?></div>
<div><strong>당월에 포함된 날짜인지 판단:</strong> <?php echo ($HiddenDate)?'미포함':'포함'; ?></div>
</td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
[/code]
댓글 2개
bamchi
11년 전
고생하셨습니다. ㅎㅎ
Terrorboy
11년 전
실제 사용 해본결과 문제가 없네요 ^^
[http://sir.co.kr/data/cheditor4/1407/b78d5034adcef6e421f2c138865330d6_1404884563_4885.png]
[http://sir.co.kr/data/cheditor4/1407/b78d5034adcef6e421f2c138865330d6_1404884563_4885.png]
게시판 목록
개발자톡
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1159 | 11년 전 | 1417 | ||
| 1158 | 11년 전 | 1585 | ||
| 1157 | 11년 전 | 631 | ||
| 1156 |
purple63
|
11년 전 | 443 | |
| 1155 | 11년 전 | 412 | ||
| 1154 | 11년 전 | 509 | ||
| 1153 |
리아빌리티
|
11년 전 | 3310 | |
| 1152 | 11년 전 | 685 | ||
| 1151 | 11년 전 | 392 | ||
| 1150 | 11년 전 | 737 | ||
| 1149 |
|
11년 전 | 853 | |
| 1148 | 11년 전 | 590 | ||
| 1147 |
리아빌리티
|
11년 전 | 511 | |
| 1146 | 11년 전 | 533 | ||
| 1145 | 11년 전 | 495 | ||
| 1144 | 11년 전 | 5426 | ||
| 1143 |
바보온달123
|
11년 전 | 622 | |
| 1142 | 11년 전 | 938 | ||
| 1141 | 11년 전 | 747 | ||
| 1140 |
DANet
|
11년 전 | 641 | |
| 1139 | 11년 전 | 1415 | ||
| 1138 | 11년 전 | 618 | ||
| 1137 | 11년 전 | 960 | ||
| 1136 | 11년 전 | 701 | ||
| 1135 | 11년 전 | 589 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기