ÔÎÄ£ºhttp://www.oschina.net/code/snippet_54698_3836
PHPÅ©Àú¹«Àúת»»
´úÂ룺
PHPÅ©Àú¹«Àúת»»
´úÂ룺
<?php if (! defined('BASEPATH')) exit('Access Denied!'); /* ÔÆÄÏÊ¡Çú¾¸Ê¦·¶Ñ§Ôº¼ÆËã»ú¿ÆѧÓ빤³ÌѧԺ-ÑÎõ±àд 2009-9-3 Å©Àú¹«Àúת»» */ class Lunar { private $_SMDay = array(1 => 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);//¶¨Ò幫ÀúÔ·ÖÌìÊý private $_LStart = 1950 ;//Å©Àú´Ó1950Ä꿪ʼ private $_LMDay = array( //²î£º¸ÃÄêµÄÅ©ÀúÕýÔ³õÒ»µ½¸ÃÄ깫Àú1ÔÂ1ÈÕµÄÌìÊý£»1~12£ºÅ©ÀúÔ·ÝÌìÊý£»Èò£ºÈçÓÐÈòÔ£¬¼Ç¼¸ÃÔÂƽÔÂÌìÊý // ²î 1 2 3 4 5 6 7 8 9 10 11 12 Èò array(47,29,30,30,29,30,30,29,29,30,29,30,29), array(36,30,29,30,30,29,30,29,30,29,30,29,30), array(6,29,30,29,30,59,29,30,30,29,30,29,30,29), //ÎåÔÂ29 ÈòÎåÔÂ30 array(44,29,30,29,29,30,30,29,30,30,29,30,29), array(33,30,29,30,29,29,30,29,30,30,29,30,30), array(23,29,30,59,29,29,30,29,30,29,30,30,30,29), //ÈýÔÂ29 ÈòÈýÔÂ30 array(42,29,30,29,30,29,29,30,29,30,29,30,30), array(30,30,29,30,29,30,29,29,59,30,29,30,29,30), //°ËÔÂ30 Èò°ËÔÂ29 array(48,30,30,30,29,30,29,29,30,29,30,29,30), array(38,29,30,30,29,30,29,30,29,30,29,30,29), array(27,30,29,30,29,30,59,30,29,30,29,30,29,30), //ÁùÔÂ30 ÈòÁùÔÂ29 array(45,30,29,30,29,30,29,30,30,29,30,29,30), array(35,29,30,29,29,30,29,30,30,29,30,30,29), array(24,30,29,30,58,30,29,30,29,30,30,30,29,29), //ËÄÔÂ29 ÈòËÄÔÂ29 array(43,30,29,30,29,29,30,29,30,29,30,30,30), array(32,29,30,29,30,29,29,30,29,29,30,30,29), array(20,30,30,59,30,29,29,30,29,29,30,30,29,30), //ÈýÔÂ30 ÈòÈýÔÂ29 array(39,30,30,29,30,30,29,29,30,29,30,29,30), array(29,29,30,29,30,30,29,59,30,29,30,29,30,30), //ÆßÔÂ30 ÈòÆßÔÂ29 array(47,29,30,29,30,29,30,30,29,30,29,30,29), array(36,30,29,29,30,29,30,30,29,30,30,29,30), array(26,29,30,29,29,59,30,29,30,30,30,29,30,30), //ÎåÔÂ30 ÈòÎåÔÂ29 array(45,29,30,29,29,30,29,30,29,30,30,29,30), array(33,30,29,30,29,29,30,29,29,30,30,29,30), array(22,30,30,29,59,29,30,29,29,30,30,29,30,30), //ËÄÔÂ30 ÈòËÄÔÂ29 array(41,30,30,29,30,29,29,30,29,29,30,29,30), array(30,30,30,29,30,29,30,29,59,29,30,29,30,30), //°ËÔÂ30 Èò°ËÔÂ29 array(48,30,29,30,30,29,30,29,30,29,30,29,29), array(37,30,29,30,30,29,30,30,29,30,29,30,29), array(27,30,29,29,30,29,60,29,30,30,29,30,29,30), //ÁùÔÂ30 ÈòÁùÔÂ30 array(46,30,29,29,30,29,30,29,30,30,29,30,30), array(35,29,30,29,29,30,29,29,30,30,29,30,30), array(24,30,29,30,58,30,29,29,30,29,30,30,30,29), //ËÄÔÂ29 ÈòËÄÔÂ29 array(43,30,29,30,29,29,30,29,29,30,29,30,30), array(32,30,29,30,30,29,29,30,29,29,59,30,30,30), //Ê®ÔÂ30 ÈòÊ®ÔÂ29 array(50,29,30,30,29,30,29,30,29,29,30,29,30), array(39,29,30,30,29,30,30,29,30,29,30,29,29), array(28,30,29,30,29,30,59,30,30,29,30,29,29,30), //ÁùÔÂ30 ÈòÁùÔÂ29 array(47,30,29,30,29,30,29,30,30,29,30,30,29), array(36,30,29,29,30,29,30,29,30,29,30,30,30), array(26,29,30,29,29,59,29,30,29,30,30,30,30,30), //ÎåÔÂ30 ÈòÎåÔÂ29 array(45,29,30,29,29,30,29,29,30,29,30,30,30), array(34,29,30,30,29,29,30,29,29,30,29,30,30), array(22,29,30,59,30,29,30,29,29,30,29,30,29,30), //ÈýÔÂ30 ÈòÈýÔÂ29 array(40,30,30,30,29,30,29,30,29,29,30,29,30), array(30,29,30,30,29,30,29,30,59,29,30,29,30,30), //°ËÔÂ30 Èò°ËÔÂ29 array(49,29,30,29,30,30,29,30,29,30,30,29,29), array(37,30,29,30,29,30,29,30,30,29,30,30,29), array(27,30,29,29,30,58,30,30,29,30,30,29,30,29), //ÎåÔÂ29 ÈòÎåÔÂ29 array(46,30,29,29,30,29,29,30,29,30,30,30,29), array(35,30,30,29,29,30,29,29,30,29,30,30,29), array(23,30,30,29,59,30,29,29,30,29,30,29,30,30), //ËÄÔÂ30 ÈòËÄÔÂ29 array(42,30,30,29,30,29,30,29,29,30,29,30,29), array(31,30,30,29,30,30,29,30,29,29,30,29,30), array(21,29,59,30,30,29,30,29,30,29,30,29,30,30), //¶þÔÂ30 Èò¶þÔÂ29 array(39,29,30,29,30,29,30,30,29,30,29,30,29), array(28,30,29,30,29,30,29,59,30,30,29,30,30,30), //ÆßÔÂ30 ÈòÆßÔÂ29 array(48,29,29,30,29,29,30,29,30,30,30,29,30), array(37,30,29,29,30,29,29,30,29,30,30,29,30), array(25,30,30,29,29,59,29,30,29,30,29,30,30,30), //ÎåÔÂ30 ÈòÎåÔÂ29 array(44,30,29,30,29,30,29,29,30,29,30,29,30), array(33,30,29,30,30,29,30,29,29,30,29,30,29), array(22,30,29,30,59,30,29,30,29,30,29,30,29,30), //ËÄÔÂ30 ÈòËÄÔÂ29 array(40,30,29,30,29,30,30,29,30,29,30,29,30), array(30,29,30,29,30,29,30,29,30,59,30,29,30,30), //¾ÅÔÂ30 Èò¾ÅÔÂ29 array(49,29,30,29,29,30,29,30,30,30,29,30,29), array(38,30,29,30,29,29,30,29,30,30,29,30,30), array(27,29,30,29,30,29,59,29,30,29,30,30,30,29), //ÁùÔÂ29 ÈòÁùÔÂ30 array(46,29,30,29,30,29,29,30,29,30,29,30,30), array(35,30,29,30,29,30,29,29,30,29,29,30,30), array(24,29,30,30,59,30,29,29,30,29,30,29,30,30), //ËÄÔÂ30 ÈòËÄÔÂ29 array(42,29,30,30,29,30,29,30,29,30,29,30,29), array(31,30,29,30,29,30,30,29,30,29,30,29,30), array(21,29,59,29,30,30,29,30,30,29,30,29,30,30), //¶þÔÂ30 Èò¶þÔÂ29 array(40,29,30,29,29,30,29,30,30,29,30,30,29), array(28,30,29,30,29,29,59,30,29,30,30,30,29,30), //ÁùÔÂ30 ÈòÁùÔÂ29 array(47,30,29,30,29,29,30,29,29,30,30,30,29), array(36,30,30,29,30,29,29,30,29,29,30,30,29), array(25,30,30,30,29,59,29,30,29,29,30,30,29,30), //ÎåÔÂ30 ÈòÎåÔÂ29 array(43,30,30,29,30,29,30,29,30,29,29,30,30), array(33,29,30,29,30,30,29,30,29,30,29,30,29), array(22,29,30,59,30,29,30,30,29,30,29,30,29,30), //ÈýÔÂ30 ÈòÈýÔÂ29 array(41,30,29,29,30,29,30,30,29,30,30,29,30), array(30,29,30,29,29,30,29,30,29,30,30,59,30,30), //ʮһÔÂ30 ÈòʮһÔÂ29 array(49,29,30,29,29,30,29,30,29,30,30,29,30), array(38,30,29,30,29,29,30,29,29,30,30,29,30), array(27,30,30,29,30,29,59,29,29,30,29,30,30,29), //ÁùÔÂ29 ÈòÁùÔÂ30 array(45,30,30,29,30,29,29,30,29,29,30,29,30), array(34,30,30,29,30,29,30,29,30,29,29,30,29), array(23,30,30,29,30,59,30,29,30,29,30,29,29,30), //ÎåÔÂ30 ÈòÎåÔÂ29 array(42,30,29,30,30,29,30,29,30,30,29,30,29), array(31,29,30,29,30,29,30,30,29,30,30,29,30), array(21,29,59,29,30,29,30,29,30,30,29,30,30,30), //¶þÔÂ30 Èò¶þÔÂ29 array(40,29,30,29,29,30,29,29,30,30,29,30,30), array(29,30,29,30,29,29,30,58,30,29,30,30,30,29), //ÆßÔÂ29 ÈòÆßÔÂ29 array(47,30,29,30,29,29,30,29,29,30,29,30,30), array(36,30,29,30,29,30,29,30,29,29,30,29,30), array(25,30,29,30,30,59,29,30,29,29,30,29,30,29), //ÎåÔÂ29 ÈòÎåÔÂ30 array(44,29,30,30,29,30,30,29,30,29,29,30,29), array(32,30,29,30,29,30,30,29,30,30,29,30,29), array(22,29,30,59,29,30,29,30,30,29,30,30,29,29), //ÈýÔÂ29 ÈòÈýÔÂ30 ); //ÊÇ·ñÈòÄê private function IsLeapYear($AYear){ return ($AYear % 4 == 0) && (($AYear % 100 != 0) || ($AYear % 400 == 0)); } //¹«Àú¸ÃÔµÄÌìÊý(year£ºÄê·Ý£» month£ºÔ·Ý) private function GetSMon($year,$month) { if($this->IsLeapYear($year) && $month == 2) return 29; else return $this->_SMDay[$month]; } //Å©ÀúÃû³Æת»» private function LYearName($year) { $Name = array("Áã","Ò»","¶þ","Èý","ËÄ","Îå","Áù","Æß","°Ë","¾Å"); for($i=0;$i<4;$i++) for($k=0;$k<10;$k++) if($year[$i]==$k) $tmp.=$Name[$k]; return $tmp; } private function LMonName($month) { if($month >=1 && $month <=12 ) { $Name = array( 1=>"Õý","¶þ","Èý","ËÄ","Îå","Áù","Æß","°Ë","¾Å","Ê®","ʮһ","Ê®¶þ"); return $Name[$month]; } return $month; } private function LDayName($day) { if($day >=1 && $day <=30 ) { $Name = array( 1 => "³õÒ»","³õ¶þ","³õÈý","³õËÄ","³õÎå","³õÁù","³õÆß","³õ°Ë","³õ¾Å","³õÊ®", "ʮһ","Ê®¶þ","Ê®Èý","Ê®ËÄ","Ê®Îå","Ê®Áù","Ê®Æß","Ê®°Ë","Ê®¾Å","¶þÊ®", "Ø¥Ò»","Ø¥¶þ","Ø¥Èý","Ø¥ËÄ","Ø¥Îå","Ø¥Áù","Ø¥Æß","Ø¥°Ë","Ø¥¾Å","ÈýÊ®" ); return $Name[$day]; } return $day; } //¹«ÀúתũÀú(Sdate£º¹«ÀúÈÕÆÚ) public function S2L($date) { list($year, $month, $day) = explode("-", $date); if($year <= 1951 || $month <= 0 || $day <= 0 || $year >= 2051 ) return false; //»ñÈ¡²éѯÈÕÆÚµ½µ±Äê1ÔÂ1ÈÕµÄÌìÊý $date1 = strtotime($year."-01-01");//µ±Äê1ÔÂ1ÈÕ $date2 = strtotime($year."-".$month."-".$day); $days=round(($date2-$date1)/3600/24); $days += 1; //»ñÈ¡ÏàÓ¦Äê¶ÈÅ©ÀúÊý¾Ý£¬»¯³ÉÊý×éLarray $Larray = $this->_LMDay[$year - $this->_LStart]; if($days <= $Larray[0]) { $Lyear = $year - 1; $days = $Larray[0] - $days; $Larray = $this->_LMDay[$Lyear - $this->_LStart]; if($days < $Larray[12]) { $Lmonth = 12; $Lday = $Larray[12] - $days; } else { $Lmonth = 11; $days = $days - $Larray[12]; $Lday = $Larray[11] - $days; } } else { $Lyear = $year; $days = $days - $Larray[0]; for($i = 1;$i <= 12;$i++) { if($days > $Larray[$i]) $days = $days - $Larray[$i]; else { if ($days > 30){ $days = $days - $Larray[13]; $Ltype = 1; } $Lmonth = $i; $Lday = $days; break; } } } return mktime(0, 0, 0, $Lmonth, $Lday, $Lyear); //$Ldate = $Lyear."-".$Lmonth."-".$Lday; //$Ldate = $this->LYearName($Lyear)."Äê".$this->LMonName($Lmonth)."ÔÂ".$this->LDayName($Lday); //if($Ltype) $Ldate.="(Èò)"; //return $Ldate; } //Å©Àúת¹«Àú(date£ºÅ©ÀúÈÕÆÚ£» type£ºÊÇ·ñÈòÔÂ) public function L2S($date,$type = 0) { list($year, $month, $day) = split("-",$date); if($year <= 1951 || $month <= 0 || $day <= 0 || $year >= 2051 ) return false; $Larray = $this->_LMDay[$year - $this->_LStart]; if($type == 1 && count($Larray)<=12 ) return false;//ÒªÇó²éѯÈò£¬µ«²éÎÞÈòÔ //Èç¹û²éѯµÄÅ©ÀúÊÇÈòÔ²¢¸ÃÄê¶ÈÅ©ÀúÊý×é´æÔÚÈòÔÂÊý¾Ý¾Í»ñÈ¡ if($Larray[$month] > 30 && $type == 1 && count($Larray) >= 13) $day = $Larray[13] + $day; //»ñÈ¡¸ÃÄêÅ©ÀúÈÕÆÚµ½¹«Àú1ÔÂ1ÈÕµÄÌìÊý $days = $day; for($i=0;$i<=$month-1;$i++) $days += $Larray[$i]; //µ±²éѯũÀúÈÕÆÚ¾àÀ빫Àú1ÔÂ1ÈÕ³¬¹ýÒ»Äêʱ if($days > 366 || ($this->GetSMon($month,2)!=29 && $days>365 )) { $Syear = $year +1; if($this->GetSMon($month,2)!=29) $days-=366; else $days-=365; if($days > $this->_SMDay[1]) { $Smonth = 2; $Sday = $days - $this->_SMDay[1]; } else { $Smonth = 1; $Sday = $days; } } else { $Syear =$year; for($i=1;$i<=12;$i++) { if($days > $this->GetSMon($Syear,$i)) $days-=$this->GetSMon($Syear,$i); else { $Smonth = $i; $Sday = $days; break; } } } return mktime(0, 0, 0, $Smonth, $Sday, $Syear); //$Sdate = $Syear."-".$Smonth."-".$Sday; //return $Sdate; } }ʹÓ÷½·¨£º
<?php require_once 'Lunar.php'; $today = date("Y-m-d"); $lunar = new Lunar(); //¹«ÀúתũÀú $nl = date("Y-m-d",$lunar->S2L($today)); //Å©Àúת¹«Àú $gl = date("Y-m-d",$lunar->L2S($nl)); echo "½ñÌ칫ÀúÊÇ:$today<br/>"; echo "תΪũÀúÊÇ:$nl<br/>"; echo "ת»Ø¹«ÀúÊÇ:$gl<br/>"; ?>
ÍƼöÐÅÏ¢
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- php³£ÓÃÕýÔò±í´ïʽ
- phpÐÔÄܼà²âÄ£¿éXHProf
- ÈÃCI¿ò¼ÜÖ§³Öservice²ã
- ʹÓÃPHPÉú³É´øLOGOµÄ¸öÐÔ»¯¶þάÂëͼÏñ
- ¹ØÓÚCodeIgniterÄã¿ÉÄܲ»ÖªµÀµÄ5¸ö֪ʶµã
- Memcache ºÁÃ뼶³¬Ê±¼°ÆäËû³£¼ûÎÊÌâ»ã×Ü
- [PHP±Ê¼Ç]PHPQueryÒ»¸ö´¦ÀíDOMµÄÀûÆ÷
ÈÈÃÅÐÅÏ¢
- nohup: redirecting stderr to stdou....
- ʹÓÃlog_formatΪNginx·þÎñÆ÷ÉèÖøüÏêϸµÄÈÕÖ¾¸ñʽ
- jquery easyUI--dataGrid-Json
- [Ô´´]·ÂGoogle Reader¡¢ÐÂÀË΢²©¡¢ÌÚѶ΢²©µ....
- ÀûÓÃKeepalived+mysql¹¹½¨¸ß¿ÉÓÃMySQLË«Ö÷×Ô¶....
- Nginx+keepalivedʵÏÖ¸ºÔؾùºâºÍË«»úÈȱ¸¸ß¿ÉÓÃ
- jqueryʵÏÖÒ³Ãæ¼ÓÔؽø¶ÈÌõ
- Rolling cURL: PHP²¢·¢×î¼Ñʵ¼ù
- codeigniter ·ÓÉÖÕ¼«ÓÅ»¯(url rewrite)
- linuxÏÂÉèÖÃsshÎÞÃÜÂëµÇ¼
×î½ü¸üÐÂ
- PHP»ñÈ¡Óû§µÄÕæʵIP£¬²¢ÅжÏÊÇ·ñÄÚÍøIP
- PHP ´íÎóÈÕÖ¾ error_log
- ÀûÓÃbigpipe»úÖÆʵÏÖÒ³ÃæÄ£¿éµÄÒì²½äÖȾ chunked¼¼Êõ
- php¿ØÖÆÎļþÏÂÔØËÙ¶È
- js + php ¶ÁÈ¡¡¢²¥·ÅÊÓƵÁ÷ ¼æÈÝfirefox£¬c....
- ¡¾ÊÓƵ²¥·Å¡¿JplayerÊÓƵ²¥·ÅÆ÷µÄʹÓÃ
- UNICODE Óë UTF-8 µÄ¹Øϵ
- memcacheÄÚ´æÔÀí
- Memcache¼¼Êõ·ÖÏí£º½éÉÜ¡¢Ê¹Óᢴ洢¡¢Ëã·¨¡¢ÓÅ»¯....
- phpʹÓÃmb_detect_encoding¼ì²â×Ö·û´®±àÂë
ÆÀÂÛ