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

天干地支,简称“干支”,这是中国古代的历法,下面使用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
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

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor