这是基于 60花甲子 计算法,用python 获取某一年的天干地支。
python code: 获取天干地支
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# -*- coding: utf-8 -*-
tiangan=[ x for x in "甲乙丙丁戊己庚辛壬癸"]
dizhi =[ x for x in "子丑寅卯辰巳午未申酉戌亥"]
td =["" ]
j=-1
for k in range(0,6):
for i in range(0,len(tiangan),1):
j=j+1
if j>= len(dizhi):
j=0
s=tiangan[i]+dizhi[j]
td.append(s)
#计算某年的农(阴)历年的天干地支
def calcYearTD( year):
try:
y = int(year)
except:
y =1
if y<1:
y = 1
y = y % 60
y = y - 3
if y<=0:
y = y+60
return td[y]
year = 1980
print( year, calcYearTD(year))
本文网址: https://pylist.com/topic/39.html 转摘请注明来源