PHP陽曆轉陰曆(農曆),陰曆轉陽曆的方法/Western Calendar To Chinese Lunar Calendar

Reference: PHP阳历转阴历(农历),阴历转阳历的方法

Due to the recent project, we need a PHP function that convert a Western calendar to Chinese Lunar Calendar.

Upon searching on the web, we found the resource above (In Simplified Chinese) that demonstrate how to do the conversion.

But there is a limit: the range is from Year 1891 to 2100.

There is also a bug in the class that, when there is a leap month, the calculation on month will be wrong.

Fortunately I (think) I solve the problem by issuing a simple "If" statement.  The full source code can be downloaded here:

https://www.mediafire.com/?6jsplf03pwpwp07

There is only 1 PHP file.  The class name is lunar.class.php

To use this class, follow the same instruction at the reference page, or here:

<?php
header("Content-Type:text/html;charset=utf-8");
$lunar=new Lunar();//http://www.phpernote.com/php-function/867.html
$month=$lunar->convertSolarToLunar(2013,07,08);//将阳历转换为阴历
echo '<pre>';
print_r($month);

Hope it helps someone.

Comments

Popular posts from this blog

TCPDF How to show/display Chinese Character?

Wordpress Load balancing: 2 web servers 1 MySQL without any Cloud services

Using wget bypass htaccess username password 401 authorization