프로그래머가 되고 나서 처음으로 달력을 짜보았습니다.
그동안 일하면서 어떻게 달력이 필요 한 작업이 하나도 없었을까요??? 아이러니 하네요 ㅎㅎㅎ
방금 하나 만들어 봤는데 유효한지 모르겠네요~
[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]
게시판 목록
개발자톡
| 번호 | 제목 | 글쓴이 | 날짜 | 조회 |
|---|---|---|---|---|
| 1259 | 11년 전 | 1040 | ||
| 1258 | 11년 전 | 2774 | ||
| 1257 | 11년 전 | 1079 | ||
| 1256 | 11년 전 | 1252 | ||
| 1255 | 11년 전 | 821 | ||
| 1254 | 11년 전 | 1136 | ||
| 1253 | 11년 전 | 1485 | ||
| 1252 | 11년 전 | 1958 | ||
| 1251 | 11년 전 | 2222 | ||
| 1250 | 11년 전 | 1089 | ||
| 1249 | 11년 전 | 1419 | ||
| 1248 | 11년 전 | 1359 | ||
| 1247 | 11년 전 | 767 | ||
| 1246 |
|
11년 전 | 3390 | |
| 1245 |
|
11년 전 | 1147 | |
| 1244 | 11년 전 | 1021 | ||
| 1243 | 11년 전 | 2160 | ||
| 1242 |
어려워요잉
|
11년 전 | 2805 | |
| 1241 |
Shhhh
|
11년 전 | 1559 | |
| 1240 | 11년 전 | 799 | ||
| 1239 |
막돼먹은영애
|
11년 전 | 1115 | |
| 1238 | 11년 전 | 1612 | ||
| 1237 |
|
11년 전 | 2375 | |
| 1236 |
|
11년 전 | 1095 | |
| 1235 | 11년 전 | 2242 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기