And everyone to share a simple calendar production process.
Basic requirements:
1. Date of acquisition
2. Get the date given
3. Get a given date is a week
4. Get Month days
5. Access to previous and next month
First put a picture of the effect, the style to do more ugly, do not like to spray.
PHP Code:
-->";
Gets the current year $year =$_get[' y ']?$_get[' y ']:d ate (' Y ');
Gets the current month $month =$_get[' m ']?$_get[' m ']:d ate (' m ');
Gets how many days of the month $days =date (' t ', Strtotime ("{$year}-{$month}-1"));
Current is the week $week =date (' W ', Strtotime ("{$year}-{$month}-1")); Content centered Show echo "
"; Print header echo "
{$year} year {$month} month
"; Print Date table echo "
"; Print Week echo "
"; echo "
| Sunday | "; echo "
Monday | "; echo "
Tuesday | "; echo "
Wednesday | "; echo "
Thursday | "; echo "
Friday | "; echo "
Saturday | "; echo "
"; Print a number for ($i =1-$week; $i <= $days;) {echo "
"; For ($j =0 $j <7; $j + +) {if ($i > $days $i<1) {echo
| "; } else{echo "
$i | "; } $i + +; } echo "
"; } echo "
"; The previous month and the next month algorithm if ($month ==1) {$prevyear = $year-1; $prevmonth = 12; }else{$prevyear = $year; $prevmonth = $month-1; } if ($month ==12) {$nextyear = $year +1; $nextmonth = 1; }else{$nextyear = $year; $nextmonth = $month +1; //Last month and next January hyperlinks echo "
last month & next month "; echo "
";?>
CSS code:
table{
width:500px;
height:300px;
Border:red dashed 1px;
Background: #ff00ff;
}
tr{
text-align:center;
}
td{
Border:gray dotted 1px;
}
h1{
font-style:italic;
font-size:50px;
font-family: ' song body ';
}
H2 a{
font-style:normal;
font-size:40px;
font-family: ' blackbody ';
color:purple;
}
/* Combination Selector *
/tr,td,th{font-size:20px;
Background:gray;
}
A few of the more error-prone and ingenious places to say:
The time stamp calculated in 1.strtotime () should be a complete format, and it is useless to put a single year or month in.
In the 2.if statement, the condition is not assigned, is equal to!!! , write two = =. This place is too easy to overlook.
3. The original print date has always been Sunday and a corresponding number. But when the month is different, the corresponding relationship between the date and the week changes, so the $i-$week in the For loop. You can take all the days of the month back a certain amount of time, to achieve the perfect correspondence between the date and the week.
4. In the implementation of the previous month and the next January function, several variables as parameters into, and then with a certain algorithm can be done. The specific look at the code, the text has to be better than to see two lines of code effect good.