Calendar Display Program

Source: Internet
Author: User
Program | calendar | Show <?php
$selectedDay = Date (' d ');
$selectedMonth = Date (' m ');
$selectedYear = Date (' Y ');
Get the first day of the month is the number of weeks
$firstday = Date (' W ', Mktime (0,0,0, $selectedMonth, 1, $selectedYear));
Find out the last day of the month
$lastday = 31;
do {
$monthOrig = Date (' m ', Mktime (0,0,0, $selectedMonth, 1, $selectedYear));
$monthTest = Date (' m ', Mktime (0,0,0, $selectedMonth, $lastday, $selectedYear));
if ($monthTest!= $monthOrig) {$lastday-= 1;}
while ($monthTest!= $monthOrig);
Get the corresponding English name for the month
$monthName = Date (' F ', Mktime (0,0,0, $selectedMonth, 1, $selectedYear));
Show Calendar Header
$days = Array ("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");
$dayRow = 0;
Print ("<table bgcolor=\" #bbFFFF \ ">");
Print ("<caption valign=\" Center\ "><b> $monthName $selectedYear </b></caption>");
Print ("<tr>\n");
For ($i =0 $i <=6; $i + +) {
Print ("<td width=10%> $days [$i]</td>\n");
}
Print ("</tr>\n");
Print ("<tr>\n");
Empty the space before the first day of the month
while ($dayRow < $firstday) {
Print ("<td><!--" month--></td> ");
$dayRow + 1;
}
$day = 0;
while ($day < $lastday) {
The following judgment statement is used to convert to the next line for every 7 time position displayed
if (($dayRow% 7) = = 0) {
Print ("</tr>\n<tr>\n");
}
$adjusted _day = $day +1;
The day's date is shown in red
if ($adjusted _day== $selectedDay) {
echo "<td><font color= #ff0000 > $adjusted _day</font></td>";
}
Else{echo "<td> $adjusted _day</td>";}
$day + 1;
$dayRow + 1;
}
Print ("\n</tr>\n</table>");
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.