Lunar Calendar-Lunar calendar-conversion class PHP version

Source: Internet
Author: User
 lunarinfo[$year-$this->min_year]; if ($year = = $this->min_year&& $month <=2&& $date <=9) {return Array (1891, ' Lunar month ', ' Junior ', ' Xin Mao ', 1, 1,        ' Rabbit '); } return $this->getlunarbybetween ($year, $this->getdaysbetweensolar ($year, $month, $date, $yearData [1],$    YEARDATA[2])); } function Convertsolarmonthtolunar ($year, $month) {$yearData = $this->lunarinfo[$year-$this->min_year        ]; if ($year = = $this->min_year&& $month <=2&& $date <=9) {return Array (1891, ' Lunar month ', ' Junior ', ' Xin Mao ', 1, 1,        ' Rabbit ');        } $month _days_ary = Array (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);        $DD = $month _days_ary[$month];        if ($this->isleapyear ($year) && $month = = 2) $dd + +;        $lunar _ary = Array (); for ($i = 1; $i < $DD; $i + +) {$array = $this->getlunarbybetween ($year, $this->getdaysbetweensolar ($yea            R, $month, $i, $yearData [1], $yearData [2]); $array [] = $year. '-' . $month. '-' .            $i;        $lunar _ary[$i] = $array;    } return $lunar _ary;     }/** * Converts the lunar calendar to Gregorian calendar * @param year Lunar calendar-years * @param month lunar calendar-months, Leap month processing: For example, if the current year leap May, then the second May will be June, equivalent to the lunar calendar has 13 months, but sometimes the 13th month of the days of 0 * @param date Lunar calendar-day */function Convertlunartosolar ($year, $month, $date) {$yearData = $this->lunarinfo[$        year-$this->min_year];        $between = $this->getdaysbetweenlunar ($year, $month, $date);        $res = Mktime (0,0,0, $yearData [1], $yearData [2], $year);        $res = Date (' y-m-d ', $res + $between *24*60*60);        $day = Explode ('-', $res);        $year = $day [0];        $m $day = $day [2];    Return Array ($year, $month, $day); }/** * Determines if a leap year is @param year */function Isleapyear ($year) {return ($year%4==0 && $year %100!=0) | |    ($year%400==0)); }/** * Get Ganzhi Calendar * @param year */function Getlunaryearname ($year) {$sky = array (' g ', ' xin ', ' ren ', ' decyl ', '   A ', ' B ', ' C ', ' ding ', ' e ', ' own ');      $earth = Array (' shen ', ' unitary ', ' Xu ', ' hai ', ' zi ', ' ugly ', ' Yin ', ' Mao ', ' Chen ', ' have ', ' noon ', ' not ');         $year = $year. ";    return $sky [$year {3}]. $earth [$year%12]; /** * Get Zodiac * @param year Lunar Year * * * * * function Getyearzodiac ($year) {$zodiac = array (' monkey ', ' chicken ', ' dog ')         ', ' pig ', ' rat ', ' ox ', ' tiger ', ' Rabbit ', ' dragon ', ' snake ', ' horse ', ' sheep ';    return $zodiac [$year%12]; }/** * Gets the number of days of the Gregorian month * @param year Gregorian-years * @param month Gregorian calendar-month */function getsolarmonthdays ($year, $month) {$monthHash = array (' 1 ' =>31, ' 2 ' = $this->isleapyear ($year)? 29:28, ' 3 ' =>31, ' 4 ' =>30, ' 5 ' =>31, ' 6 ' =&G         T;30, ' 7 ' =>31, ' 8 ' =>31, ' 9 ' =>30, ' ten ' =>31, ' one ' =>30, ' one ' =>31 ';    return $monthHash ["$month"]; }/** * Gets the number of days of the lunar month * @param year lunar calendar-years * @param month lunar calendar-month, starting from January */function Getlunarmonthdays ($year, $         Month) {$monthData = $this->getlunarmonths ($year);    return $monthData [$month-1]; /** * Gets an array of days of the lunar calendar per month * @param year */function GetluNarmonths ($year) {$yearData = $this->lunarinfo[$year-$this->min_year];        $leapMonth = $yearData [0];        $bit = Decbin ($yearData [3]);        for ($i = 0; $i < strlen ($bit); $i + +) {$bitArray [$i] = substr ($bit, $i, 1);        } for ($k =0, $klen =16-count ($bitArray), $k < $klen; $k + +) {array_unshift ($bitArray, ' 0 '); } $bitArray = Array_slice ($bitArray, 0, ($leapM for ($i =0; $i
 
  
lunarinfo[$year-$this->min_year];        $monthArray = $this->getlunaryearmonths ($year);        $len = count ($monthArray);    Return ($monthArray [$len -1]==0? $monthArray [$len-2]: $monthArray [$len-1]);        } function Getlunaryearmonths ($year) {//debugger;        $monthData = $this->getlunarmonths ($year);        $res =array ();        $temp = 0;        $yearData = $this->lunarinfo[$year-$this->min_year];        $len = ($yearData [0]==0?12:13);            for ($i =0; $i < $len; $i + +) {$temp = 0;            for ($j =0; $j <= $i; $j + +) {$temp + = $monthData [$j];        } array_push ($res, $temp);    } return $res; /** * Get Leap Month * @param year lunar years */function Getleapmonth ($year) {$yearData = $this->lunarinfo[        $year-$this->min_year];    return $yearData [0]; /** * Calculates the number of days between lunar dates and the day of the month * @param year * @param month * @param date */function Getdaysbetweenlu NAR ($year, $month, $Date) {$yearMonth = $this->getlunarmonths ($year);        $res = 0;        for ($i =1; $i < $month; $i + +) {$res + = $yearMonth [$i-1];        } $res + = $date-1;    return $res;     */** * Calculates the number of days between 2 Gregorian dates * @param year Gregorian * @param cmonth * @param cdate * @param the Gregorian month corresponding to the lunar month of Dmonth * @param ddate Lunar calendar days */function Getdaysbetweensolar ($year, $cmonth, $cdate, $dmonth, $ddate) {$a = mk        Time (0,0,0, $cmonth, $cdate, $year);        $b = Mktime (0,0,0, $dmonth, $ddate, $year);    Return Ceil (($a-$b)/24/3600); /** * Calculates the lunar date based on the number of days from the day of the month * @param year Gregorian * @param between days */function Getlunarbybetween ($year,        $between) {//debugger;        $lunarArray = Array ();        $yearM $t = 0;        $e = 0;        $leapM $m = ";            if ($between ==0) {Array_push ($lunarArray, $year, ' The lunar month ', ' the Junior ');            $t = 1;        $e = 1;  }else{$year = $between >0? $year: ($year-1);          $yearMonth = $this->getlunaryearmonths ($year);            $leapMonth = $this->getleapmonth ($year);            $between = $between >0? $between: ($this->getlunaryeardays ($year) + $between);                    for ($i =0; $i <13; $i + +) {if ($between = = $yearMonth [$i]) {$t = $i +2;                    $e = 1;                Break                    }else if ($between < $yearMonth [$i]) {$t = $i +1;                    $e = $between-(Empty ($yearMonth [$i-1])? 0: $yearMonth [$i-1]) +1;                Break }} $m = ($leapMonth!=0&& $t = = $leapMonth + 1)? (' Leap '. $this->getcapitalnum ($t -1,true)): $this->getcapitalnum (($leapMonth!=0&& $leapMonth +1< $t? (            $t-1): $t), true);        Array_push ($lunarArray, $year, $m, $this->getcapitalnum ($e, false));        } array_push ($lunarArray, $this->getlunaryearname ($year));//Zodiac earthly Array_push ($lunarArray, $t, $e); Array_push ($lunarArray, $tHis->getyearzodiac ($year));//12 Zodiac Array_push ($lunarArray, $leapMonth);//leap months return $lunarArray; }/** * Gets the number of the lunar term * @param num number * @param ismonth is the number of months */function Getcapitalnum ($num, $isMonth)        {$isMonth = $isMonth | | false; $dateHash =array (' 0 ' = ', ' 1 ' = ' one ', ' 2 ' = ' two ', ' 3 ' = ' three ', ' 4 ' = ' Four ', ' 5 ' = ' five ', ' 6 ' = ' Six ', ' 7 ' = ' Seven '        , ' 8 ' = ' eight ', ' 9 ' = ' nine ', ' ten ' = ' x ';        $m $res = ";        if ($isMonth) {$res = $monthHash [$num];            }else{if ($num <=10) {$res = ' early '. $dateHash [$num];            }else if ($num >10&& $num <20) {$res = ' ten '. $dateHash [$num-10];            }else if ($num ==20) {$res = "20";            }else if ($num >20&& $num <30) {$res = "20". $dateHash [$num-20];            }else if ($num ==30) {$res = "30";    }} return $res; }} $lunar = new lunar (); $month = $luNar->convertlunartosolar (;p) Rint_r ($month); exit; 
 

The above describes the lunar-lunar-conversion PHP version, including the aspects of the content, I hope to be interested in PHP tutorial friends helpful.

  • Related Article

    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.