Home php教程 php手册 php实现天干地支计算器示例

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

Jun 06, 2016 pm 08:24 PM

天干地支,简称“干支”,这是中国古代的历法,下面使用php实现一个天干地支计算器,需要的朋友可以参考下

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

天干地支算法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 . "]年
";
}
?>


 

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

Repo: How To Revive Teammates
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)