php准确计算复活节日期的方法

这篇文章主要介绍了php准确计算复活节日期的方法,涉及php操作日期的技巧,非常具有实用价值,需要的朋友可以参考下,本文实例讲述了php准确计算复活节日期的方法,分享给大家供大家参考,具体如下:

  1. <?PHP
  2. function isLeapYear( $nYEAR ) {
  3. if((($nYEAR % 4 == 0) AND !($nYEAR % 100 == 0)) AND ($nYEAR % 400 != 0))
  4. {
  5. return TRUE;
  6. } else {
  7. return FALSE;
  8. }
  9. }
  10. function div( $a, $b ){
  11. return( $a - ( $a % $b )) / $b;
  12. }
  13. function easterSunday( $nYEAR ) {
  14. // The function is able to calculate the date
  15. //of eastersunday back to the year 325,
  16. // but mktime() starts at 1970-01-01!
  17. if ( $nYEAR < 1970 ) {
  18. $dtEasterSunday = mktime( 1,1,1,1,1,1970 );
  19. } else {
  20. $nGZ = ( $nYEAR % 19 ) + 1;
  21. $nJHD = div( $nYEAR, 100 ) + 1;
  22. $nKSJ = div( 3 * $nJHD, 4 ) - 12;
  23. $nKORR = div( 8 * $nJHD + 5, 25 ) - 5;
  24. $nSO = div( 5 * $nYEAR, 4 ) - $nKSJ - 10;
  25. $nEPAKTE = (( 11 * $nGZ + 20 + $nKORR - $nKSJ ) % 30 );
  26. if (( $nEPAKTE == 25 OR $nGZ == 11 ) AND $nEPAKTE == 24 ) {
  27. $nEPAKTE = $nEPAKTE + 1;
  28. }
  29. $nN = 44 - $nEPAKTE;
  30. if( $nN < 21 ) {
  31. $nN = $nN + 30;
  32. }
  33. $nN = $nN + 7 - (( $nSO + $nN ) % 7 );
  34. $nN = $nN + isLeapYear( $nYEAR );
  35. $nN = $nN + 59;
  36. $nA = isLeapYear( $nYEAR );
  37. // Month
  38. $nNM = $nN;
  39. if ( $nNM > ( 59 + $nA )) {
  40. $nNM = $nNM + 2 - $nA;
  41. }
  42. $nNM = $nNM + 91;
  43. $nMONTH = div( 20 * $nNM, 611 ) - 2;
  44. // Day
  45. $nNT = $nN;
  46. $nNT = $nN;
  47. if ( $nNT > ( 59 + $nA )) {
  48. $nNT = $nNT + 2 - $nA;
  49. }
  50. $nNT = $nNT + 91;
  51. $nM = div( 20 * $nNT, 611 );
  52. $nDAY = $nNT - div( 611 * $nM, 20 );
  53. $dtEasterSunday = mktime( 0,0,0,$nMONTH,$nDAY,$nYEAR );
  54. }
  55. return $dtEasterSunday;
  56. }
  57. ?>