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:

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:

$lunar=new Lunar();//
echo '<pre>';

Hope it helps someone.


Popular posts from this blog

TCPDF How to show/display Chinese Character?

Using wget bypass htaccess username password 401 authorization

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