public function getLunarDate($y, $m, $d) { $y = $y < 1900 ? 1900 : $y; // 保存公历信息 $this->year = $y; $this->month = $m; $this->day = $d; // 使用扩展库计算当年的春节日期 $data = lunar_get_lunardate($y, $m, $d); // 填充星期信息 $this->weekday = $data['weekday']; // 填充农历信息 $this->lunarYear = $data['lunar_year']; //年 $this->lunarMonth = $data['lunar_month']; //月 $this->lunarDay = $data['lunar_day']; //日 $this->lunarIsLeapMonth = $data['lunar_isleap']; //是否闰月 // 返回自身 return $this; }
<?php $br = php_sapi_name() == "cli" ? "" : "<br>"; if (!extension_loaded('jlunar')) { dl('php_jlunar.' . PHP_SHLIB_SUFFIX); } $module = 'jlunar'; $functions = get_extension_funcs($module); echo "Functions available in the test extension:{$br}\n"; foreach ($functions as $func) { echo $func . "{$br}\n"; } echo "{$br}\n"; $str = lunar_get_todaystring(); echo "{$str}\n"; $str = lunar_get_today(); var_dump($str); $str = lunar_get_date(100); var_dump($str); $str = lunar_get_lunardate(2012, 6, 29); var_dump($str); $str = lunar_get_solardate(2012, 5, 12); var_dump($str); $str = lunar_get_solardate(2012, 4, 18, 1); var_dump($str); $spring = lunar_get_spring(2012); var_dump($spring); echo lunar_get_weekday(2012, 6, 30);