$Lunar_Month = array(
/* 1881 */ // 1881³â 1¿ù 30ÀÏÀº À½·Â 1¿ù 1ÀÏ
"1","2","1","2","1","2","2","3","2","2","1","2","1", "1","2","1","2","1","2","1","2","2","1","2","2","0",
"1","1","2","1","1","2","1","2","2","2","1","2","0", "2","1","1","2","1","3","2","1","2","2","1","2","2",
"2","1","1","2","1","1","2","1","2","1","2","2","0", "2","1","2","1","2","1","1","2","1","2","1","2","0",
"2","2","1","2","3","2","1","1","2","1","2","1","2", "2","1","2","2","1","2","1","1","2","1","2","1","0",
"2","1","2","2","1","2","1","2","1","2","1","2","0", "1","2","3","2","1","2","2","1","2","1","2","1","2",
/*1891*/
"1","2","1","2","1","2","1","2","2","1","2","2","0", "1","1","2","1","1","2","3","2","2","1","2","2","2",
"1","1","2","1","1","2","1","2","1","2","2","2","0", "1","2","1","2","1","1","2","1","2","1","2","2","0",
"2","1","2","1","2","3","1","2","1","2","1","2","1", "2","2","2","1","2","1","1","2","1","2","1","2","0",
"1","2","2","1","2","1","2","1","2","1","2","1","0", "2","1","2","3","2","2","1","2","1","2","1","2","1",
"2","1","2","1","2","1","2","2","1","2","1","2","0", "1","2","1","1","2","1","2","2","3","2","2","1","2",
/*1901*/
"1","2","1","1","2","1","2","1","2","2","2","1","0", "2","1","2","1","1","2","1","2","1","2","2","2","0",
"1","2","1","2","1","3","2","1","1","2","2","1","2", "2","2","1","2","1","1","2","1","1","2","2","1","0",
"2","2","1","2","2","1","1","2","1","2","1","2","0", "1","2","2","1","4","1","2","1","2","1","2","1","2",
"1","2","1","2","1","2","2","1","2","1","2","1","0", "2","1","1","2","2","1","2","1","2","2","1","2","0",
"1","2","3","1","2","1","2","1","2","2","2","1","2", "1","2","1","1","2","1","2","1","2","2","2","1","0",
/*1911*/
"2","1","2","1","1","2","3","1","2","2","1","2","2", "2","1","2","1","1","2","1","1","2","2","1","2","0",
"2","2","1","2","1","1","2","1","1","2","1","2","0", "2","2","1","2","2","3","1","2","1","2","1","1","2",
"2","1","2","2","1","2","1","2","1","2","1","2","0", "1","2","1","2","1","2","2","1","2","1","2","1","0",
"2","1","3","2","1","2","2","1","2","2","1","2","1", "2","1","1","2","1","2","1","2","2","2","1","2","0",
"1","2","1","1","2","1","2","3","2","2","1","2","2", "1","2","1","1","2","1","1","2","2","1","2","2","0",
/*1921*/
"2","1","2","1","1","2","1","1","2","1","2","2","0", "2","1","2","2","1","3","2","1","1","2","1","2","2",
"1","2","2","1","2","1","2","1","2","1","1","2","0", "2","1","2","1","2","2","1","2","1","2","1","1","0",
"2","1","2","2","3","2","1","2","2","1","2","1","2", "1","1","2","1","2","1","2","2","1","2","2","1","0",
"2","1","1","2","1","2","1","2","2","1","2","2","0", "1","2","3","1","2","1","1","2","2","1","2","2","2",
"1","2","1","1","2","1","1","2","1","2","2","2","0", "1","2","2","1","1","2","3","1","2","1","2","2","1",
/*1931*/
"2","2","2","1","1","2","1","1","2","1","2","1","0", "2","2","2","1","2","1","2","1","1","2","1","2","0",
"1","2","2","1","2","4","1","2","1","2","1","1","2", "1","2","1","2","2","1","2","2","1","2","1","2","0",
"1","1","2","1","2","1","2","2","1","2","2","1","0", "2","1","1","4","1","2","1","2","1","2","2","2","1",
"2","1","1","2","1","1","2","1","2","2","2","1","0", "2","2","1","1","2","1","1","4","1","2","2","1","2",
"2","2","1","1","2","1","1","2","1","2","1","2","0", "2","2","1","2","1","2","1","1","2","1","2","1","0",
/*1941*/
"2","2","1","2","2","1","4","1","1","2","1","2","1", "2","1","2","2","1","2","2","1","2","1","1","2","0",
"1","2","1","2","1","2","2","1","2","2","1","2","0", "1","1","2","1","4","1","2","1","2","2","1","2","2",
"1","1","2","1","1","2","1","2","2","2","1","2","0", "2","1","1","2","1","1","2","1","2","2","1","2","0",
"2","2","3","1","2","1","1","2","1","2","1","2","2", "2","1","2","1","2","1","1","2","1","2","1","2","0",
"2","2","1","2","1","2","1","3","2","1","2","1","2", "2","1","2","2","1","2","1","1","2","1","2","1","0",
/*1951*/
"2","1","2","2","1","2","1","2","1","2","1","2","0", "1","2","1","2","1","4","2","1","2","1","2","1","2",
"1","2","1","1","2","2","1","2","2","1","2","2","0", "1","1","2","1","1","2","1","2","2","1","2","2","0",
"2","1","1","4","1","1","2","1","2","1","2","2","2", "1","2","1","2","1","1","2","1","2","1","2","2","0",
"2","1","2","1","2","1","1","2","3","2","1","2","2", "1","2","2","1","2","1","1","2","1","2","1","2","0",
"1","2","2","1","2","1","2","1","2","1","2","1","0", "2","1","2","1","2","2","3","2","1","2","1","2","1",
/*1961*/
"2","1","2","1","2","1","2","2","1","2","1","2","0", "1","2","1","1","2","1","2","2","1","2","2","1","0",
"2","1","2","1","3","2","1","2","1","2","2","2","1", "2","1","2","1","1","2","1","2","1","2","2","2","0",
"1","2","1","2","1","1","2","1","1","2","2","1","0", "2","2","2","3","2","1","1","2","1","1","2","2","1",
"2","2","1","2","2","1","1","2","1","2","1","2","0", "1","2","2","1","2","1","2","3","2","1","2","1","2",
"1","2","1","2","1","2","2","1","2","1","2","1","0", "2","1","1","2","2","1","2","1","2","2","1","2","0",
/*1971*/
"1","2","1","1","2","3","2","1","2","2","2","1","2", "1","2","1","1","2","1","2","1","2","2","2","1","0",
"2","1","2","1","1","2","1","1","2","2","2","1","0", "2","2","1","2","3","1","2","1","1","2","2","1","2",
"2","2","1","2","1","1","2","1","1","2","1","2","0", "2","2","1","2","1","2","1","2","3","2","1","1","2",
"2","1","2","2","1","2","1","2","1","2","1","1","0", "2","2","1","2","1","2","2","1","2","1","2","1","0",
"2","1","1","2","1","2","4","1","2","2","1","2","1", "2","1","1","2","1","2","1","2","2","1","2","2","0",
/*1981*/
"1","2","1","1","2","1","1","2","2","1","2","2","0", "2","1","2","1","3","2","1","1","2","2","1","2","2",
"2","1","2","1","1","2","1","1","2","1","2","2","0", "2","1","2","2","1","1","2","1","1","2","3","2","2",
"1","2","2","1","2","1","2","1","1","2","1","2","0", "1","2","2","1","2","2","1","2","1","2","1","1","0",
"2","1","2","2","1","2","3","2","2","1","2","1","2", "1","1","2","1","2","1","2","2","1","2","2","1","0",
"2","1","1","2","1","2","1","2","2","1","2","2","0", "1","2","1","1","2","3","1","2","1","2","2","2","2",
/*1991*/
"1","2","1","1","2","1","1","2","1","2","2","2","0", "1","2","2","1","1","2","1","1","2","1","2","2","0",
"1","2","2","3","2","1","2","1","1","2","1","2","1", "2","2","2","1","2","1","2","1","1","2","1","2","0",
"1","2","2","1","2","2","1","2","3","2","1","1","2", "1","2","1","2","2","1","2","1","2","2","1","2","0",
"1","1","2","1","2","1","2","2","1","2","2","1","0", "2","1","1","2","1","3","2","2","1","2","2","2","1",
"2","1","1","2","1","1","2","1","2","2","2","1","0", "2","2","1","1","2","1","1","2","1","2","2","1","0",
/*2001*/
"2","2","2","1","3","2","1","1","2","1","2","1","2", "2","2","1","2","1","2","1","1","2","1","2","1","0",
"2","2","1","2","2","1","2","1","1","2","1","2","0", "1","2","3","2","2","1","2","1","2","2","1","1","2",
"1","2","1","2","1","2","2","1","2","2","1","2","0", "1","1","2","1","2","1","2","3","2","2","1","2","2",
"1","1","2","1","1","2","1","2","2","2","1","2","0", "2","1","1","2","1","1","2","1","2","2","1","2","0",
"2","2","1","1","2","3","1","2","1","2","1","2","2", "2","1","2","1","2","1","1","2","1","2","1","2","0",
/*2011*/
"2","1","2","2","1","2","1","1","2","1","2","1","0", "2","1","2","4","2","1","2","1","1","2","1","2","1",
"2","1","2","2","1","2","1","2","1","2","1","2","0", "1","2","1","2","1","2","1","2","2","3","2","1","2",
"1","2","1","1","2","1","2","2","2","1","2","2","0", "1","1","2","1","1","2","1","2","2","1","2","2","0",
"2","1","1","2","1","3","2","1","2","1","2","2","2", "1","2","1","2","1","1","2","1","2","1","2","2","0",
"2","1","2","1","2","1","1","2","1","2","1","2","0", "2","1","2","2","3","2","1","1","2","1","2","1","2",
/*2021*/
"1","2","2","1","2","1","2","1","2","1","2","1","0", "2","1","2","1","2","2","1","2","1","2","1","2","0",
"1","2","3","2","1","2","1","2","2","1","2","1","2", "1","2","1","1","2","1","2","2","1","2","2","1","0",
"2","1","2","1","1","2","3","2","1","2","2","2","1", "2","1","2","1","1","2","1","2","1","2","2","2","0",
"1","2","1","2","1","1","2","1","1","2","2","2","0", "1","2","2","1","2","3","1","2","1","1","2","2","1",
"2","2","1","2","2","1","1","2","1","1","2","2","0", "1","2","1","2","2","1","2","1","2","1","2","1","0",
/*2031*/
"2","1","2","3","2","1","2","2","1","2","1","2","1", "2","1","1","2","1","2","2","1","2","2","1","2","0",
"1","2","1","1","2","1","2","3","2","2","2","1","2", "1","2","1","1","2","1","2","1","2","2","2","1","0",
"2","1","2","1","1","2","1","1","2","2","1","2","0", "2","2","1","2","1","1","4","1","1","2","1","2","2",
"2","2","1","2","1","1","2","1","1","2","1","2","0", "2","2","1","2","1","2","1","2","1","1","2","1","0",
"2","2","1","2","2","3","2","1","2","1","2","1","1", "2","1","2","2","1","2","2","1","2","1","2","1","0",
/*2041*/
"2","1","1","2","1","2","2","1","2","2","1","2","0", "1","2","3","1","2","1","2","1","2","2","2","1","2",
"1","2","1","1","2","1","1","2","2","1","2","2","0"
);
function is_yun_year($year)
{
if ($year % 4 != 0) return 0; /* not yun year */
if ($year % 100 != 0) return 1; /* yun year */
if ($year % 400 != 0) return 0; /* not yun year */
return 1; /* yun year */
}
function how_many_days($year, $month)
{
switch($month)
{
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
return 31;
case 4: case 6: case 9: case 11:
return 30;
case 2:
if (is_yun_year($year)) return 29;
else return 28;
}
}
function end_day_of_lunar_month($year, $month)
{
global $Lunar_Month;
for ($i = 0; $i < $month; $i++) {
$flag = $Lunar_Month[$year-1880][$i];
if ($flag == '3' || $flag == '4') break;
}
if ($i != month)
$flag = $Lunar_Month[($year-1880)*13+$month];
else $flag = $Lunar_Month[($year-1880)*13+$month-1];
if ($flag == '1') return 29;
else return 30;
}
function solar_to_lunar($year, $month, $day)
{
global $Lunar_Month , $lunar_date;
$total_day = 0;
// ÇØÀÇ ¹üÀ§¸¦ ÃøÁ¤ÇÑ´Ù.
if ($year < 1881 || $year > 2043) return -1;
for ($i = 0; $i < 163; $i++) {
$Sum_of_Lunar_Day[$i]=0; // 1³âÀÇ À½·Â ³¯ÀÚÀÇ ÇÕÀ» ÀúÀåÇÏ´Â ¹è¿
$list_of_year[$i]=1881+$i;
for ($j = 1; $j <= 13; $j++) {
$this_month = $i*13+$j-1;
switch($Lunar_Month[$this_month]) {
case '0':
break;
case '1': case '3':
$Sum_of_Lunar_Day[$i] = $Sum_of_Lunar_Day[$i] + 29;
$imsi=29;
break;
case '2': case '4':
$Sum_of_Lunar_Day[$i] = $Sum_of_Lunar_Day[$i] + 30;
$imsi=30;
break;
}
}
}
/* ¿À´Ã±îÁöÀÇ ¾ç·Â ³¯ÀÚÀÇ ÇÕ±¸Çϱâ. */
/* 1881-1-30ÀÌ À½·Â 1¿ù 1ÀÏÀ̳ª±ñ 1880³â±îÁö ³¯¿¡ 29ÀÏÀ» ´õÇÑ´Ù. */
$sum_of_1881 = (int)(1880*365 + 1880/4 - 1880/100 + 1880/400 + 29);
/* ÀԷ¹ÞÀº ³¯±îÁöÀÇ ³¯Â¥ÀÇ ÇÕ±¸Çϱâ */
//--- À۳⠱îÁöÀÇ ³¯Â¥ÀÇ ÇÕ ---//
$last_year=$year-1;
$sum_of_today = (int)($last_year*365 + $last_year/4 - $last_year/100 + $last_year/400);
//--- ÀÚ³ ´Þ ±îÁöÀÇ ³¯Â¥ÀÇ ÇÕ ---//
for($i = 1; $i < $month ; $i++){
$sum_of_today = $sum_of_today + how_many_days($year,$i);
}
//--- ¿À´Ã±îÁöÀÇ ³¯Â¥ÀÇ ÇÕ ---//
$sum_of_today = $sum_of_today + $day;
// ¿À´Ã±îÁöÀÇ ³¯Â¥ ÇÕ¿¡¼ 1881³â 1¿ù 29ÀÏÀÇ ³¯Â¥ÀÇ ÇÕÀ» »«´Ù.//
// $total_day´Â ³¯Â¥ÀÇ Â÷ÀÌ..
if($year == 1881) $total_day = $sum_of_today - $sum_of_1881;
else $total_day = $sum_of_today - $sum_of_1881 -1;
//--------------------------------------------------------------------//
// ÀÌÁ¦ ºÎÅÍ À½·ÂÀ» °è»ê ÇÑ´Ù..
$total_imsi = $Sum_of_Lunar_Day[0];
for($i = 0; $i < 163; $i++) {
if ($total_day <= $total_imsi) break;
else $total_imsi = $total_imsi + $Sum_of_Lunar_Day[$i + 1];
}
$lun_year = $i + 1881; // À½·Â ³âµµ ±¸ÇÔ..
$ext_total_day = $total_day - $total_imsi + $Sum_of_Lunar_Day[$i];;
if ($Lunar_Month[$i*13+12] == '0') $count = 12;
else $count = 13;
$m2 = 0;
for ($j = 0; $j < $count; $j++) {
$this = $i*13+$j;
if ($Lunar_Month[$this] == 1) {
$m2++;
$m1 = $Lunar_Month[$this] + 28;
$is_yun_month = 0;
}
else if ($Lunar_Month[$this] == 2) {
$m2++;
$m1 = $Lunar_Month[$this] + 28;
$is_yun_month = 0;
}
else if ($Lunar_Month[$this] == 3) {
$m1 = $Lunar_Month[$this] + 26;
$is_yun_month = 1;
}
else {
$m1 = $Lunar_Month[$this] + 26;
$is_yun_month = 1;
}
// ´ÙÀ½´ÞÀÌ À±´ÞÀÎÁö ¾Æ´ÑÁö¸¦ ¸®ÅÏÇÑ´Ù..
// ³Ñ±â´Â ÀÌÀ¯´Â »ýÀÏÀÚÀÇ Äõ¸® Àü¼ÛÀ» À§Çؼ..
// À½·Â À±´ÞÀÇ »ýÀÏÀÚ ¶Ç´Â Æò´Þ¿¡ ÅÂ¾î³ »ýÀÏÀÚ°¡
// À±´ÞÀÌ ´ÙÀ½´Þ¿¡µµ ³ª¿ÀÁö ¾Ê°Ô.
// ±×·¯´Ï±ñ »ýÀÏÀÌ µÎ¹ø »ý±âÁö ¾Êµµ·Ï
$next = $i*13+$j+1;
if ($Lunar_Month[$next] == 1) $next_is_yun_month = 0;
else if ($Lunar_Month[$next] == 2) $next_is_yun_month = 0;
else if ($Lunar_Month[$next] == 3) $next_is_yun_month = 1;
else $next_is_yun_month = 1;
if ($ext_total_day <= $m1) break;
$ext_total_day = $ext_total_day - $m1;
}
$lunar_year = $lun_year;
$lunar_month = $m2;
$lunar_day = (int)($ext_total_day);
$is_lunar = $is_yun_month;
$next_is_lunar =$next_is_yun_month;
if($lunar_month <10) $lunar_month="0".$lunar_month;
if($lunar_day <10) $lunar_day="0".$lunar_day;
$lunar_date = "$lunar_year"."³â"." "."$lunar_month"."¿ù"." "."$lunar_day"."ÀÏ";
return $lunar_date;
}
$Y = date("Y");
$M = date("m");
$D = date("d");
solar_to_lunar($Y, $M, $D);
echo $lunar_date;
|
|