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 32 33 34 35 36
| def getGanZhiBySolarDay(year,month,day): ''' 使用高氏日柱法 :param year: str: 公历年 :param month: str: 公里月 :param day: str: 公历日 :return: str: 干支 ''' 干支 = ["甲子", "乙丑", "丙寅", "丁卯", "戊辰", "己巳", "庚午", "辛未", "壬申", "癸酉", "甲戌", "乙亥", "丙子", "丁丑", "戊寅", "己卯", "庚辰", "辛巳", "壬午", "癸未", "甲申", "乙酉", "丙戌", "丁亥", "戊子", "己丑", "庚寅", "辛卯", "壬辰", "癸巳", "甲午", "乙未", "丙申", "丁酉", "戊戌", "己亥", "庚子", "辛丑", "壬寅", "癸卯", "甲辰", "乙巳", "丙午", "丁未", "戊申", "己酉", "庚戌", "辛亥", "壬子", "癸丑", "甲寅", "乙卯", "丙辰", "丁巳", "戊午", "己未", "庚申", "辛酉", "壬戌", "癸亥"]
世纪常数 = {"17":3,"18":47,"19":31,"20":15,"21":0,"22":44,"23":28,"24":12,"25":57,"26":41} 月基数= [0,0,31,-1,30,0,31,1,32,3,33,4,34]
s = int(year[-2:]) - 1
s4 = int(s / 4) if year[-2:] == '00': s4 = -1
u = s % 4 x = 世纪常数[str(int(year[:-2]) + 1)] m = 月基数[int(month)] d = int(day)
r = s4 * 6 + 5 * (s4 * 3 + u) + m + d + x
r = r % 60 - 1
if (int(year) % 100 != 0 and int(year) % 4 == 0) or (int(year) % 400 == 0): if int(month) > 2: r += 1
return 干支[r]
|