php实现天干地支计算器示例_PHP

WBOY
Release: 2016-06-01 11:55:38
Original
1137 people have browsed it

天干地支,简称“干支”。在中国古代的历法中,甲、乙、丙、丁、戊、己、庚、辛、壬、癸被称为“十天干”,子、丑、寅、卯、辰、巳、午、未、申、酉、戌、亥叫作“十二地支”。十干和十二支依次相配,组成六十个基本单位,两者按固定的顺序互相配合,组成了干支纪法。从殷墟出土的甲骨文来看,天干地支在我国古代主要用于纪日,此外还曾用来纪月、纪年、纪时等。

天干地支算法1

天干地支算法:

一.公元后的:
天干:甲4 乙5 丙6 丁7 戊8 己9 庚0 辛1 壬2 癸3
如1894年末尾一个数是4就甲年,依此类推

地支:子4 丑5 寅6 卯7 辰8 巳9 午10 未11 申0 酉1 戌2 亥3 
换算:1894除以12,余数是几,就在地支中找几

二.公元前的:
天干:甲7 乙6 丙5 丁4 戊3 己2 庚1 辛0 壬9 癸8
如公元前7年就是甲年依此类推

地支:子-9 丑-8 寅-7 卯-6 辰-5 巳-4 午-3 未-2 申-1 酉0 戌-11 亥-10
换算:如公元前221年,-221除以12,余数是几,就在地支中找几

复制代码 代码如下:
$TGDZ = array (array ('甲', '乙', '丙', '丁', '戊', '己', '庚', '辛', '壬', '癸' ),
array ('子', '丑', '寅', '卯', '辰', '巳', '午', '未', '申', '酉', '戌', '亥' ) );
$Year = 2014;
$Year_JiSuan = $Year - 1900 + 36;
$TianGanDiZhi = $TGDZ[0][$Year_JiSuan % 10] . $TGDZ[1][$Year_JiSuan % 12];
echo $Year."年为农历[".$TianGanDiZhi."]年";
?>

天干地支算法2

复制代码 代码如下:
$TGDZ = array (array ('庚', '辛', '壬', '癸' ,'甲', '乙', '丙', '丁', '戊', '己'), array ( '申', '酉', '戌', '亥', '子', '丑', '寅', '卯', '辰', '巳', '午', '未') );
for ($Year = 1900; $Year {
$TianGanDiZhi = $TGDZ[0][$Year % 10] . $TGDZ[1][$Year % 12];
echo $Year . "年为农历[" . $TianGanDiZhi . "]年
";
}
?>

 

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!