import java.util.*/**规则在这里 http://www.zdic.net/appendix/f2.htm 超过字数了 我吧缩进删了*/public class SolarTerm {public static void main(String[] s) throws Exception{SolarTerm st = new SolarTerm()if(s.length == 3){System.out.println(st.getSoralTerm(Integer.parseInt(s[0]), Integer.parseInt(s[1]), Integer.parseInt(s[2])))}System.out.println(st.getSoralTerm(2009, 1, 5))System.out.println(st.getSoralTerm(2009, 1, 20))System.out.println(st.getSoralTerm(2009, 1, 23))System.out.println(st.getSoralTerm(2009, 2, 18))}final static long[] STermInfo = new long[] { 0, 21208, 42467, 63836, 85337,107014, 128867, 150921, 173149, 195551, 218072, 240693, 263343,285989, 308563, 331033, 353350, 375494, 397447, 419210, 440795,462224, 483532, 504758 }private static final String[] SolarTerm = new String[] { "小寒", "大寒", "立春", "雨水","惊蛰", "春分", "清明", "谷雨", "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋","处暑", "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至"}public SolarTerm(){}/** 核心方法 根据日期得到
节气 */public String getSoralTerm(Date Date){Calendar cal = Calendar.getInstance()cal.setTime(Date)int y = cal.get(Calendar.YEAR)int m = cal.get(Calendar.MONTH) + 1int d = cal.get(Calendar.DAY_OF_MONTH)return getSoralTerm(y, m, d)}/** 核心方法 根据日期(y年m月d日)得到节气 */public String getSoralTerm(int y, int m, int d){String solarTermsif (d == sTerm(y, (m - 1) * 2)) solarTerms = SolarTerm[(m - 1) * 2]else if (d == sTerm(y, (m - 1) * 2 + 1)) solarTerms = SolarTerm[(m - 1) * 2 + 1]else{//到这里说明非节气时间 solarTerms = ""}return solarTerms}// ===== y年的第n个节气为几日(从0小寒起算)private int sTerm(int y, int n) {Calendar cal = Calendar.getInstance()cal.set(1900, 0, 6, 2, 5, 0)long temp = cal.getTime().getTime()cal.setTime(new Date( (long) ((31556925974.7 * (y - 1900) + STermInfo[n] * 60000L) + temp)))return cal.get(Calendar.DAY_OF_MONTH)}}
你可以用一份用于C语言的数据得到,Java和C语言有相似处,数据也是可以通用的。
我这里有一个数据提取工具,可以提取范围从公元1600年到公元6400年之间的四千八百年之间的任意年份区间的数据,非常好用,算法也有源代码。
//
农历月份信息。一年用3个字节表示
//+-------------------------------------------------------------------------+
//| 第23位 | 第22-17位 | 第16-13位 | 第12-0位 |
//|--------+------------------------+------------+--------------------------|
//| 保留 | 农历正月初一的年内序数 | 闰月 | 一个比特对应一个月份大小 |
//+-------------------------------------------------------------------------+
//月份大小数据是月份小的在低位,月份大的在高位,即正月在最低位。
//以1900年为例,3个字节的数据展开成二进制位:
// 0 011110 1000 1 0 1 1 0 1 1 0 1 0 0 1 0
//保留 1月31日(春节) 闰八月 从左往右依次十二月,十一月……闰八月、八月、七月……正月的天数
//农历月份对应的位为0,表示这个月为29天(小月),为1表示有30天(大月)。
0x58,0x0B,0xA5,0x42,0x0B,0x49,0x2C,0x5A,0x93,0x52,0x0A,0x95,0x3D,0x35,0x2D, //1600-1604
0x60,0x05,0x56,0x4A,0x0A,0xB5,0x36,0xD5,0xAA,0x5C,0x05,0xD2,0x44,0x0D,0xA5, //1605-1609
0x30,0x7D,0x4A,0x56,0x0D,0x4A,0x41,0x6A,0x95,0x62,0x0A,0x97,0x4E,0x05,0x56, //1610-1614
0x39,0x0A,0xB5,0x5E,0x0A,0xD9,0x48,0x06,0xD2,0x32,0x8E,0xA5,0x58,0x0F,0x25, //1615-1619
0x44,0x06,0x4A,0x2A,0x4C,0x97,0x50,0x0A,0xAB,0x3D,0x55,0x5A,0x62,0x05,0x6A, //1620-1624
0x4A,0x0B,0x69,0x36,0xD7,0x52,0x5C,0x07,0x92,0x46,0x0B,0x25,0x2E,0x96,0x4B, //1625-1629
……
你用用看吧,应该能用的。
评论列表(0条)