Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Calendar.php 2.6 KiB

il y a 3 ans
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. *
  4. * ============================================================================
  5. * * 版权所有 蜘蛛出行 * *
  6. * 网站地址: http://www.zzcx.com
  7. * ----------------------------------------------------------------------------
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和
  9. * 使用;不允许对程序代码以任何形式任何目的的再发布。
  10. * ============================================================================
  11. * Author By: 温依莅
  12. * PhpStorm Calendar.php
  13. * Create By 2017/3/20 15:19 $
  14. */
  15. namespace common\models;
  16. class Calendar
  17. {
  18. protected $_table;//table表格
  19. protected $_currentDate;//当前日期
  20. protected $_year; //年
  21. protected $_month; //月
  22. protected $_days; //给定的月份应有的天数
  23. protected $_dayofweek;//给定月份的 1号 是星期几
  24. /**
  25. * 构造函数
  26. */
  27. public function __construct($y,$m)
  28. {
  29. $this->_table="";
  30. $this->_year = $y==0?date("Y"):$y;
  31. $this->_month = $m==0?date("m"):str_pad($m,2,'0',STR_PAD_LEFT);
  32. if ($this->_month>12){//处理出现月份大于12的情况
  33. $this->_month=1;
  34. $this->_year++;
  35. }
  36. if ($this->_month<1){//处理出现月份小于1的情况
  37. $this->_month=12;
  38. $this->_year--;
  39. }
  40. $this->_days = date("t",mktime(0,0,0,$this->_month,1,$this->_year));//得到给定的月份应有的天数
  41. $this->_dayofweek = date("w",mktime(0,0,0,$this->_month,1,$this->_year));//得到给定的月份的 1号 是星期几
  42. }
  43. /**
  44. * 输出日历
  45. */
  46. public function showCalendar()
  47. {
  48. $ycount=ceil(($this->_days+($this->_dayofweek%7))/7);
  49. $total=7*$ycount;
  50. $headEmpty=$this->_dayofweek;
  51. $endEmpty=$total-$this->_days-$headEmpty;
  52. //生成日期数组
  53. $list=array();
  54. for($i=1;$i<=$total;$i++){
  55. if($i<=$headEmpty||$i>$total-$endEmpty){
  56. $list[$i]=array();
  57. }else{
  58. $day= str_pad($i-$headEmpty,2,'0',STR_PAD_LEFT);
  59. $date="$this->_year-$this->_month-$day";
  60. $list[$i]['date']=$date;
  61. $list[$i]['day']=$i-$headEmpty;
  62. }
  63. }
  64. // $data['ycount']=$ycount;
  65. // $data['total']=$total;
  66. // $data['head']=$headEmpty;
  67. // $data['end']=$endEmpty;
  68. $data['list']=$list;
  69. $data['year']=$this->_year;
  70. $data['month']=$this->_month;
  71. return $data;
  72. }
  73. }