php日历代码 三个不错的php日历代码

原创
2016-07-25 08:56:04 1558浏览
  1. /**
  2. * php日历
  3. * by bbs.it-home.org
  4. */
  5. if (function_exists('date_default_timezone_set')) {
  6. date_default_timezone_set('Asia/Chongqing');
  7. }
  8. $date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d');
  9. $date = getdate(strtotime($date));
  10. $end = getdate(mktime(0, 0, 0, $date['mon'] + 1, 1, $date['year']) - 1);
  11. $start = getdate(mktime(0, 0, 0, $date['mon'], 1, $date['year']));
  12. $pre = date('Y-m-d', $start[0] - 1);
  13. $next = date('Y-m-d', $end[0] + 86400);
  14. $html = '';
  15. $html .= '
  16. ';
  17. $html .= '
  18. ';
  19. $html .= '
  20. ';
  21. $html .= '
  22. ';
  23. $html .= '
  24. ';
  25. $arr_tpl = array(0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '');
  26. $date_arr = array();
  27. $j = 0;
  28. for ($i = 0; $i if (!isset($date_arr[$j])) {
  29. $date_arr[$j] = $arr_tpl;
  30. }
  31. $date_arr[$j][($i+$start['wday'])%7] = $i+1;
  32. if ($date_arr[$j][6]) {
  33. $j++;
  34. }
  35. }
  36. foreach ($date_arr as $value) {
  37. $html .= '
  38. ';
  39. foreach ($value as $v) {
  40. if ($v) {
  41. if ($v == $date['mday']) {
  42. $html .= '
  43. ';
  44. } else {
  45. $html .= '
  46. ';
  47. }
  48. } else {
  49. $html .= '
  50. ';
  51. }
  52. }
  53. $html .= '
  54. ';
  55. }
  56. $html .= '
  57. -' . $date['year'] . ';' . $date['month'] . '+
    ' . $v . '' . $v . '
    ';
  58. echo $html;
  59. ?>
复制代码

2,php日历代码2

  1. /**
  2. * 日历
  3. */
  4. if (function_exists('date_default_timezone_set')) {
  5. date_default_timezone_set('Asia/Chongqing');
  6. }
  7. $date = isset($_GET['date']) ? $_GET['date'] : date('Y-m-d');
  8. $date = getdate(strtotime($date));
  9. $end = getdate(mktime(0, 0, 0, $date['mon'] + 1, 1, $date['year']) - 1);
  10. $start = getdate(mktime(0, 0, 0, $date['mon'], 1, $date['year']));
  11. $pre = date('Y-m-d', $start[0] - 1);
  12. $next = date('Y-m-d', $end[0] + 86400);
  13. $html = 'align="center" style="line-height:150%; font-family:Verdana,宋体; font-size: 12px;">';
  14. $html .= '
  15. ';
  16. $html .= '
  17. ';
  18. $html .= '
  19. ';
  20. $html .= '
  21. ';
  22. $html .= '
  23. ';
  24. $arr_tpl = array(0 => '', 1 => '', 2 => '', 3 => '', 4 => '', 5 => '', 6 => '');
  25. $date_arr = array();
  26. $j = 0;
  27. for ($i = 0; $i if (!isset($date_arr[$j])) {
  28. $date_arr[$j] = $arr_tpl;
  29. }
  30. $date_arr[$j][($i+$start['wday'])%7] = $i+1;
  31. if ($date_arr[$j][6]) {
  32. $j++;
  33. }
  34. }
  35. foreach ($date_arr as $value) {
  36. $html .= '
  37. ';
  38. foreach ($value as $v) {
  39. if ($v) {
  40. if ($v == $date['mday']) {
  41. $html .= '
  42. ';
  43. } else {
  44. $html .= '
  45. ';
  46. }
  47. } else {
  48. $html .= '
  49. ';
  50. }
  51. }
  52. $html .= '
  53. ';
  54. }
  55. $html .= '
  56. -' . $date['year'] . ';' . $date['month'] . '+
    ' . $v . '' . $v . '
    ';
  57. echo $html;
  58. ?>
复制代码

3,php日历代码三:

  1. /**

  2. * php日历代码
  3. * edit: bbs.it-home.org
  4. */
  5. function calendar()
  6. {
  7. if($_GET['ym'])
  8. {
  9. $year = substr($_GET['ym'],0,4);
  10. $month = substr($_GET['ym'],4,(strlen($_GET['ym'])-4));
  11. if($month>12)

  12. {
  13. $year += floor($month/12);
  14. $month = $month % 12;
  15. }
  16. if($year > 2030) $year = 2030;
  17. if($year }
  18. $year = isset($year) ? $year : date('Y');

  19. $month = isset($month) ? $month : date('n');
  20. if($year==date('Y') && $month==date('n')) $today = date('j');

  21. if($month-1 == 0)

  22. $prevmonth = ($year - 1)."12";
  23. else $prevmonth = $year.($month - 1);
  24. if($month+1 == 13)

  25. $nextmonth = ($year+1)."1";
  26. else $nextmonth = $year.($month+1);
  27. $prevyear = ($year - 1).$month;

  28. $nextyear = ($year + 1).$month;
  29. echo

  30. VKN;
  31. $nowtime = mktime(0,0,0,$month,1,$year);//当月1号转为秒
  32. $daysofmonth = date(t,$nowtime);//当月天数
  33. $weekofbeginday = date(w,$nowtime);//当月第一天是星期几
  34. $weekofendday = date(w,mktime(0,0,0,$month+1,0,$year));//当月最后一天是星期几
  35. $daysofprevmonth = date(t,mktime(0,0,0,$month,0,$year));//上个月天数
  36. $count = 1;//计数

  37. //列出上月后几天
  38. for($i = 1 ; $i {
  39. echo "
  40. ";
  41. $count++;
  42. }
  43. //当月全部
  44. for($i = 1 ; $i {
  45. $css = ($count%7==0 || $count%7==1)?"weekday":"normalday";
  46. if($i == $today) $css .= "today";
  47. echo "

  48. ";
  49. if($count%7==0) echo "
  50. ";
  51. $count++;
  52. }
  53. //下月前几天
  54. for ($i = 1;$i {
  55. echo "
  56. ";
  57. }
  58. echo

  59. $year - $month > >>
    ".($daysofprevmonth-$weekofbeginday+$i)."".$i."
    ".$i."
  60. VKN;
  61. }
  62. ?>
  63. calendar
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。