当前位置:Gxlcms > PHP教程 > 日历有关问题

日历有关问题

时间:2021-07-01 10:21:17 帮助过:47人阅读

日历问题
2012年02月
星期一 星期二 星期三 星期四 星期五 星期六 星期日
6 7 8 9 10 11 12
13 14 15 16 17 18 19



帮忙写写。谢谢

------解决方案--------------------
PHP code
  1. <!--?php
  2. class calendar{
  3. private $year;
  4. private $month;
  5. private $day_week;
  6. function __construct(){
  7. $this--->year=isset($_GET['year']) ? $_GET['year'] : date("Y");
  8. $this->month=isset($_GET['month']) ? $_GET['month'] : date("m");
  9. $this->day_week=date("w", mktime(0, 0, 0, $this->month, 1, $this->year));
  10. }
  11. private function xianDate(){
  12. echo "";
  13. echo "nextyear($this->year, $this->month)."'>"."<<<"."";
  14. echo "nextmonth($this->month, $this->year)."'>"."<<"."";
  15. echo "".$this->year."年".$this->month."月";
  16. echo "aftermonth($this->month, $this->year)."'>".">>"."";
  17. echo "afteryear($this->year, $this->month)."'>".">>>"."";
  18. echo "";
  19. }
  20. private function weeks(){
  21. $weeks=array("日", "一", "二", "三", "四", "五", "六");
  22. echo "";
  23. foreach($weeks as $value){
  24. echo "".$value."";
  25. }
  26. echo "";
  27. }
  28. private function days(){
  29. echo "";
  30. for($i=0; $i<$this->day_week; $i++){
  31. echo " ";
  32. }
  33. for($j=1; $j <= date("t", mktime(0, 0, 0, $this->month, 1, $this->year)); $j++){
  34. $i++;
  35. if($j == date("d")){
  36. echo "".$j."";
  37. }else{
  38. echo "".$j."";
  39. }
  40. if($i%7 == 0){
  41. echo "";
  42. }
  43. }
  44. while($i%7 != 0){
  45. echo " ";
  46. $i++;
  47. }
  48. }
  49. private function nextyear($year, $month){
  50. if($year == 1970){
  51. $year=1970;
  52. }else{
  53. $year--;
  54. }
  55. return "?year=".$year."&month=".$month;
  56. }
  57. private function afteryear($year, $month){
  58. if($year == 2038){
  59. $year=2038;
  60. }else{
  61. $year++;
  62. }
  63. return "?year=".$year."&month=".$month;
  64. }
  65. private function nextmonth($month, $year){
  66. if($month == 1){
  67. $year--;
  68. $month=12;
  69. }else{
  70. $month--;
  71. }
  72. return "?year=".$year."&month=".$month;
  73. }
  74. private function aftermonth($month, $year){
  75. if($month == 12){
  76. $year++;
  77. $month=1;
  78. }else{
  79. $month++;
  80. }
  81. return "?year=".$year."&month=".$month;
  82. }
  83. public function out(){
  84. echo "";
  85. $this->xianDate();
  86. $this->weeks();
  87. $this->days();
  88. echo "<table align="center"></table>";
  89. }
  90. }
  91. $a=new calendar;
  92. $a->out();
  93. ?>

人气教程排行