Php calendar code efficient calendar code implemented by php

Source: Internet
Author: User
Php calendar code efficient calendar code implemented by php

  1. /*

  2. * Php calendar
  3. * Edit: bbs.it-home.org
  4. */
  5. @ Date_default_timezone_set ('rpc ');

  6. Function show_calender (){

  7. $ Starttime = microtime ();

  8. // Request processing date

  9. $ Y = isset ($ _ GET ["y"])? Intval ($ _ GET ["y"]): date ("Y ");
  10. $ M = isset ($ _ GET ["m"])? Intval ($ _ GET ["m"]): date ("m ");
  11. If ($ m <1 | $ m> 12) $ m = date ("m ");
  12. If ($ y <= 0) $ y = date ("Y ");

  13. // Next month

  14. $ Nm = $ m + 1;
  15. If ($ nm> 12 ){
  16. $ Nm = 1;
  17. $ Ny = $ y + 1;
  18. } Else {
  19. $ Ny = $ y;
  20. }

  21. // January 1, January

  22. $ Pm = M-1;
  23. If ($ pm <1 ){
  24. $ Pm = 12;
  25. $ Py = $ Y-1;
  26. } Else {
  27. $ Py = $ y;
  28. }

  29. // Obtain the name of this month

  30. $ Month = date ("M", mktime (0, 0, 0, $ m, 1, $ y ));

  31. // Obtain the last day of the month

  32. $ Lastday = date ("d", mktime (0, 0, 0, $ nm, 0, $ ny ));

  33. // Obtain the day of the week from the start day

  34. $ Index = date ("w", mktime (0, 0, 0, $ m, 1, $ y ));

  35. // Generate the calendar header

  36. Echo"

  37. // Process calendar

  38. If ($ row = 0 ){
  39. Else
  40. } Else {
  41. Else
  42. }
  43. $ Row ++;
  44. $ Row = 0;
  45. $ Day = 1;
  46. While (1 ){
  47. Echo"
  48. For ($ I = 0; $ I <= 6; $ I ++)
  49. If ($ I <$ index)
  50. Echo"
  51. Echo"
  52. For ($ I = 0; $ I <= 6; $ I ++)
  53. If ($ day> $ lastday)
  54. Echo"
  55. Echo"
  56. Echo"
  57. If ($ day> $ lastday) break;
  58. }
  59. Echo"
  60. \ N \ N "; "; "; "; "; "; ";
    - {$ Y} {$ month} +
    Day I II 3. Thu V. Sat.
     ". $ Day ++ ." ". $ Day ++ ."
    ";

  61. $ Endtime = microtime ();

  62. $ Usedtime = $ endtime-$ starttime;
  63. Return $ usedtime;
  64. }

  65. $ Run_info = array ();

  66. For ($ I = 0; $ I <10; $ I ++)
  67. $ Run_info [] = show_calender ();

  68. Print_r ($ run_info );

  69. ?>

Test results:

Array ([0] => 0.00038400000000005 [1] => 0.00030999999999998 [2] => 0.00029699999999999 [3] => 0.000303 [4] => 0.00030399999999997 [5] => 0.00034499999999998 [6] => 0.00032300000000002 [7] => 0.00033 [8] => 0.00032699999999997 [9] => 0.00032000000000004)

>>> Articles you may be interested in: php calender calendar code (solving 2038 issues) php calendar code (with demo effect) php calendar code sharing simple and practical php calendar code three good php calendar code sharing a PHP simple calendar code php simple calendar implementation code (events can be bound)

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.