$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;
첫댓글 몬지 잘 모르겠네염~^^