天天看点

php使用intl获取农历

$date = \IntlCalendar::createInstance(NULL, '[email protected]=chinese');// 使用农历

$format = new \IntlDateFormatter('zh_CN', \IntlDateFormatter::FULL, \IntlDateFormatter::FULL, null, $date, 'U年M月d日 HH:mm:ss');// 这里的格式化要使用ICU的格式
// 参考:http://userguide.icu-project.org/formatparse/datetime

echo $format->format(strtotime('2017-12-01 16:11:04'));// 输出:丁酉年10月14日 16:11:04

echo $format->format(time());// 输出:己亥年12月12日 16:16:37
           

php5.4以后是自带intl扩展的,但是需要开启。