Created
March 10, 2011 03:03
-
-
Save riaf/863507 to your computer and use it in GitHub Desktop.
カレンダーっぽい感じのあれ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function getCalendar($date) { | |
if ($date instanceof DateTime === false) { | |
$date = new DateTime($date); | |
} | |
$sdate = clone $date; | |
$sdate->modify('first day of'); | |
$edate = clone $sdate; | |
$edate->modify('+1 month'); | |
if ($sdate->format('w')) { | |
$sdate->modify('last sunday'); | |
} | |
if ($edate->format('w')) { | |
$edate->modify('next sunday'); | |
} | |
$period = new DatePeriod( | |
$sdate, | |
new DateInterval('P1D'), | |
$edate | |
); | |
return $period; | |
} | |
foreach (getCalendar(new DateTime('+1 month')) as $k => $d) { | |
if ($k !== 0 && $k % 7 === 0) { | |
echo PHP_EOL; | |
} | |
echo $d->format("\td"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment