欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-01-29 20:03:52
本文实例讲述了php准确计算复活节日期的方法。分享给大家供大家参考。具体如下:

本文实例讲述了php准确计算复活节日期的方法。分享给大家供大家参考。具体如下:

<?php
function isleapyear( $nyear ) {
 if((($nyear % 4 == 0) and !($nyear % 100 == 0)) and ($nyear % 400 != 0))
 {
  return true;
 } else {
  return false;
 }
}
function div( $a, $b ){
 return( $a - ( $a % $b )) / $b;
}
function eastersunday( $nyear ) {
 // the function is able to calculate the date 
 //of eastersunday back to the year 325,
 // but mktime() starts at 1970-01-01!
 if ( $nyear < 1970 ) {
  $dteastersunday = mktime( 1,1,1,1,1,1970 );
 } else {
  $ngz = ( $nyear % 19 ) + 1;
  $njhd = div( $nyear, 100 ) + 1;
  $nksj = div( 3 * $njhd, 4 ) - 12;
  $nkorr = div( 8 * $njhd + 5, 25 ) - 5;
  $nso = div( 5 * $nyear, 4 ) - $nksj - 10;
  $nepakte = (( 11 * $ngz + 20 + $nkorr - $nksj ) % 30 );
  if (( $nepakte == 25 or $ngz == 11 ) and $nepakte == 24 ) {
   $nepakte = $nepakte + 1;
  }
  $nn = 44 - $nepakte;
  if( $nn < 21 ) {
   $nn = $nn + 30;
  }
  $nn = $nn + 7 - (( $nso + $nn ) % 7 );
  $nn = $nn + isleapyear( $nyear );
  $nn = $nn + 59;
  $na = isleapyear( $nyear );
  // month
  $nnm = $nn;
  if ( $nnm > ( 59 + $na )) {
   $nnm = $nnm + 2 - $na;
  }
  $nnm = $nnm + 91;
  $nmonth = div( 20 * $nnm, 611 ) - 2;
  // day
  $nnt = $nn;
  $nnt = $nn;
  if ( $nnt > ( 59 + $na )) {
   $nnt = $nnt + 2 - $na;
  }
  $nnt = $nnt + 91;
  $nm = div( 20 * $nnt, 611 );
  $nday = $nnt - div( 611 * $nm, 20 );
  $dteastersunday = mktime( 0,0,0,$nmonth,$nday,$nyear );
 }
 return $dteastersunday;
}
?>

希望本文所述对大家的php程序设计有所帮助。