根据万年历算八字

本文介绍了生辰八字的概念,农历与阳历的区别,以及如何根据农历和天干地支计算生辰八字。通过解析农历数据,利用天干地支的循环规律,可以推算出生辰八字,但需要注意闰月的影响。文章还提到验证方法,通过与香港天文台数据核对确保准确性。
摘要由CSDN通过智能技术生成

生辰八字,每逢结婚生子的时候,总会从长辈的口中念叨出来。那到底什么是生辰八字呢?难到只有算命先生知道?是一门玄学?

其实不是,在我国,有农历和阳历两种纪年方法。而阳历属于舶来品,也是当下采用的历法。
但是在古代,我们采用的是农历。农历是一种阴阳历。古人认为太阳属阳, 月亮属阴。结合太阳和月亮的公转周期,加以“闰月"调和而形成的。调和的目的是因为: 地球围绕太阳转一圈(一年)的时间,并不严格等于月亮绕地球转十二圈的时间。而农历里面的节气是和农耕生活息息相关的,所以需要天文学家夜观天象去看,去算。也就是说,这个闰月不是固定的,要根据当年具体的温度和湿度,选择闰到哪一月,才能保证不误农时。

而古代是不采用数字纪年的,而是用对应的汉字表示。汉字分为两类,天干和地支。

  • 天干是: “甲”, “乙”, “丙”, “丁”, “戊”, “己”, “庚”, “辛”, “壬”, “癸”
  • 地支是: “子”, “丑”, “寅”, “卯”, “辰”, “巳”, “午”, “未”, “申”, “酉”, “戌”, “亥”

根据天干地址的排列组合,生成六十个组合, 写个脚本体验下:

#!/usr/bin/python3

heavenlyStreams = ["甲", "乙", "丙", "丁", "戊", "己", "庚", "辛", "壬", "癸"]
earthlyBranches = ["子", "丑", "寅", "卯", "辰", "巳", "午", "未", "申", "酉", "戌", "亥"] 

m = 0
n = 0
for i in range(0,60):
   print('"'+heavenlyStreams[m%10] + earthlyBranches[n%12]  + '",', end =' ')
   m = m + 1
   n = n + 1

说道这里,八字就是年月日时所代表的八个子。我们先说前面六个字. 比如2019年7月29日.翻阅万年历:

2019年7月

阳历 2019年7月29日. 就是己亥(年)辛未(月)丁卯(日),也就是农历2019年六月廿七日。

那问题来了,如何根据阳历找到对应的六字呢?网上有一些公式。仔细研究后发现对应年初的月份是不行的。因为这时阳历一个月里面,会跨度阴历的两个月。而公式算法的输入只有年份和月份,所以对于年初,结果必然是不准确的。

我的思路是:

  • 从本质上将,所谓的年月日,就是天干地支所组合的60个字的循环。比如这次是甲子,那下次就该用乙丑了。
  • 那我只需要知道某一天的信息,就可以根据天数推算出后面的信息了。
  • 因为闰月不是固定的, 也就是说,我要搞到一份靠谱的农历数据。

撤远一点,我们用的农历又叫夏历,是因为不同的朝代,会选择不同的字作为开头。而夏朝代是以寅开头。现在沿用了这一方式。所以也叫夏历。

靠谱的数据源可以在香港天文台拿到, 搞了一个自动下载脚本。懒得挨个去点了。

wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1901c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1902c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1903c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1904c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1905c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1906c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1907c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1908c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1909c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1910c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1911c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1912c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1913c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1914c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1915c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1916c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1917c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1918c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1919c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1920c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1921c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1922c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1923c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1924c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1925c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1926c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1927c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1928c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1929c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1930c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1931c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1932c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1933c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1934c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1935c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1936c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1937c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1938c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1939c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1940c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1941c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1942c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1943c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1944c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1945c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1946c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1947c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1948c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1949c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1950c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1951c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC  https://data.weather.gov.hk/gts/time/calendar/text/T1952c.txt 
wget --local-encoding=ENC   --remote-encoding=ENC
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值