农历php,PHP农历公历转换

/*

云南省曲靖师范学院计算机科学与工程学院-杨海熙编写

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;

}

}

?>

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/501824.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

python迷宫起点终点所有路径_通向终点的路不止一条!python迷宫。

马上注册&#xff0c;结交更多好友&#xff0c;享用更多功能^_^您需要 登录 才可以下载或查看&#xff0c;没有帐号&#xff1f;立即注册x本帖最后由 wei_Y 于 2014-11-24 19:53 编辑2008121223547917.jpg (56.62 KB, 下载次数: 3)2014-11-17 19:22 上传其实木有上面那么高端啦…

恶意软件分析沙箱在网络安全策略中处于什么位置?

恶意软件分析沙箱提供了一种全面的恶意软件分析方法&#xff0c;包括静态和动态技术。这种全面的评估可以更全面地了解恶意软件的功能和潜在影响。然而&#xff0c;许多组织在确定在其安全基础设施中实施沙箱的最有效方法方面面临挑战。让我们看一下可以有效利用沙盒解决方案的…

php websocket 帧封装,swoole websocket封装类和调用

上代码 ws.php/*** ws 优化 基础类库* User: singwa* Date: 18/3/2* Time: 上午12:34*/class Ws {CONST HOST "0.0.0.0";CONST PORT 9512;public $ws null;public function __construct() {$this->ws new swoole_websocket_server("0.0.0.0", 9512)…

夸克浏览器怎么安装脚本_广告看烦了?别砸手机!这五款浏览器能拯救你

哈喽大家好&#xff0c;欢迎来到黑马公社。随着各种良莠不齐的内容开始泛滥&#xff0c;黑马发现自己很难通过网络第一时间找到自己想要的内容。在电脑上&#xff0c;黑马为自己的每个浏览器都安装了不下三个广告屏蔽插件&#xff0c;而在手机上&#xff0c;很难。先不说手机浏…

php 今天 明天 后天 显示10天,【微信小程序】实现含有今天,明天,后天的日期组件...

封面图.JPG前言做过微信小程序的前端er都知道&#xff0c;小程序有个日期组件&#xff0c;叫picker&#xff0c;但是&#xff0c;需求方要求日期和时间都要显示的&#xff0c;用picker组件的话&#xff0c;那就用到两个picker&#xff0c;date和time&#xff0c;就是说要让用户…

python dlib 年龄 性别_python dlib学习(一):人脸检测

1、环境安装Windows&#xff1a; 旧版本安装pip install xxx.whl。以下是whl文件地址&#xff1a; ​ Python Package Index​ 最新版本安装&#xff1a;不要嫌麻烦&#xff0c;先装上visual studio2015 (C模块)。​ 具体的记不清了&#xff0c;装上cmake和boost&#xff0c;然…

php数组实例,php常用数组函数实例小结

本文实例总结了php常用数组函数。分享给大家供大家参考&#xff0c;具体如下&#xff1a;1. array array_merge(array $array1 [, array $array2 [, $array]])函数功能&#xff1a;将一个或多个数组的单元合并起来&#xff0c;一个数组中的值附加在前一个数组的后面。返回结果的…

python预测控制_无人驾驶——4.控制之MPC模型预测控制

源自&#xff1a;《无人驾驶无人驾驶车辆模型预测控制》——龚建伟参考&#xff1a;https://wenku.baidu.com/view/8e4633d519e8b8f67c1cb9fa.html0.车辆模型汽车的车轮转角为δf分别做垂直于后轮和前轮的射线&#xff0c;这两根射线会交于O点&#xff0c;两轮模型会绕O点进行运…

php实现git服务器,如何搭建和配置Git服务器

本篇文章给大家带来的内容是介绍如何搭建和配置Git服务器&#xff0c;有一定的参考价值&#xff0c;有需要的朋友可以参考一下&#xff0c;希望对你有所帮助。安装Git安装依赖yum install curl-devel expat-devel gcc gcc-cyum install perl perl-devel gettext-devel openssl-…

手机连接投影机的步骤_投影机安装过程详解

投影机安装过程详解一 投影机的安装方式1、桌面摆放桌面投影虽然看起来不是很美观&#xff0c;但可以省去那些繁琐的步骤&#xff0c;只需要准备一张桌子&#xff0c;还可以购买一些专门用来摆放投影机的可移动小车架&#xff0c;把投影机往上一放&#xff0c;连接上线缆就可以…

php memcached close,PHP连接Memcached安装及数据库操作

memcached介绍Memcached是一套开源的高性能分布式内存对象缓存系统,它将所有的数据都存储在内存中,因为在内存中会统一维护一张巨大的Hash表,所以支持任意存储类型的数据。很多网站通过使用 Memcached提高网站的访问速度,尤其是对于大型的需要频繁访问数据的网站。Memcached是典…

坏道修复是不是硬盘东西全部都没有了_硬盘有坏道就不能用了吗?别再吃哑巴亏了,今天跟大家再说一次...

硬盘是电脑的存储硬件&#xff0c;是电脑中核心的硬件之一&#xff0c;目前市场上主要使用的是固态硬盘与机械硬盘两种&#xff0c;固态硬盘的读写速度较快&#xff0c;容量小&#xff0c;价格贵&#xff0c;机械硬盘读写速度慢&#xff0c;容量大价格便宜&#xff0c;现在的电…

html5+php调用android手机图片,html5+exif.js+canvas+php实现手机上传图片,图片损坏无法打开...

上传图片&#xff0c;图片损坏无法打开&#xff0c;图片路径也是正确的&#xff0c;function selectFileImage(fileObj) {var file fileObj.files[0];//图片方向角 added by lzkvar Orientation null;if (file) {console.log("正在上传,请稍后...");var rFilter /…

word 编辑域中的汉字_15条Word常用操作教程,简单实用,纯干货分享,收藏备用!...

点击蓝字关注我们1. 去除页眉横线在页眉插入信息的时候经常会在下面出现一条横线&#xff0c;如果这条横线影响你的视觉。这时你可以采用下述的两种方法去掉&#xff1a;用第一种的朋友比较多&#xff0c;即选中页眉的内容后&#xff0c;选取“格式”选项&#xff0c;选取“边框…

matlab里面连接器是什么,连接器

连接器连接器&#xff0c;即CONNECTOR。国内亦称作接插件、插头和插座。一般是指电连接器。即连接两个有源器件的器件&#xff0c;传输电流或信号。它广泛应用于航空、航天、国防等军用系统中。连接器是我们电子工程技术人员经常接触的一种部件。它的作用非常单纯&#xff1a;在…

安卓抓包软件_Packet Capture安卓抓包神器介绍及使用教程

除了干货&#xff0c;其他什么也没有源码&#xff5c;资源&#xff5c;软件&#xff5c;教程&#xff5c;揭秘关 注Packet Capture是一款安卓抓包软件&#xff0c;能用来提取用户操作程序内容&#xff0c;Packet Capture可以捕获网络数据包&#xff0c;并记录它们使用中间人技术…

队列处理高并发_高并发场景下缓存处理的一些思路

在实际的开发当中&#xff0c;我们经常需要进行磁盘数据的读取和搜索&#xff0c;因此经常会有出现从数据库读取数据的场景出现。但是当数据访问量次数增大的时候&#xff0c;过多的磁盘读取可能会最终成为整个系统的性能瓶颈&#xff0c;甚至是压垮整个数据库&#xff0c;导致…

多元线性回归分析matlab实验报告,利用MATLAB进行多元线性回归.ppt

《利用MATLAB进行多元线性回归.ppt》由会员分享&#xff0c;可在线阅读&#xff0c;更多相关《利用MATLAB进行多元线性回归.ppt(15页珍藏版)》请在人人文库网上搜索。1、2.线性回归,bregress(y,X) b,bint,r,rint,sregress(y,X,alpha),输入: y因变量(列向量), X1与自变量组成的矩…

python3.6安装tensorflow gpu_tensorflow-gpu安装的常见问题及解决方案

装tensorflow-gpu的时候经常遇到问题&#xff0c;自己装过几次&#xff0c;经常遇到相同或者类似的问题&#xff0c;所以打算记录一下&#xff0c;也希望对其他人有所帮助基本信息tensorflow-gpupip安装(virtualenv等虚拟安装实质也是pip安装&#xff0c;只是建了个独立的环境&…

php env 没有值,PHP DOTENV无法加载env变种

我正在使用php dotenv for env vars for my php application .自述文件说我可以将 php dotenv 加载到我的应用程序中&#xff1a;$dotenv new Dotenv\Dotenv(__DIR__);$dotenv->load();当我尝试登录时&#xff0c;出现500错误 . 我试着 var_dump ing我的 $dotenv var看看它…