package cn.bupt; public class RiLi { public static String[] tiangan = {"庚","辛","壬","癸","甲","乙","丙","丁","戊","己"};//天干 public static String[] tianganQ = {"辛","庚","己","戊","丁","丙","乙","甲","癸","壬"};//天干公元前 public static String[] dizhi = {"申","酉","戌","亥","子","丑","寅","卯","辰","巳","午","未"};//地支 public static String[] dizhiQ = {"酉","申","未","午","巳","辰","卯","寅","丑","子","亥","戌"};//地支公元前 //公元元年对应西汉末期,公元1年,9岁的汉平帝刘衎登 // // 计算公式:[Y*D+C]-L // // 公式解读:数2位乘0.2422加3.87取整数减闰数21世纪C值=3.87 22世纪C值=4.15 // // 举例说明:2058立春期计算步骤[58×.0.2422+3.87]-[(58-1)/4]=17-14=3则2月3立春 public static void main(String[] args) { /* for(int i = 3000;i>0;i--){ getGanZhi(i+"",true); } for(int i = 1;i<2016;i++){ getGanZhi(i+"",false); }*/ System.out.println(getliChun("2014")); } public static String getliChun(String myDate){ int tian = Integer.parseInt(myDate.substring(myDate.length() - 2)); float lic = (float) (tian * 0.2422 + 3.87 - ((tian - 1) / 4)); return myDate + "年,立春是是2月" + (Math.floor(lic) + "").split("\\.")[0] + "号"; } public static void getGanZhi(String myDate,boolean isQian){ int tian = Integer.parseInt(myDate.substring(myDate.length() - 1)); int di = Integer.parseInt(myDate) % 12; if (!isQian) System.out.println(myDate + "年,干支纪年是:" + tiangan[tian] + dizhi[di]);// 公元 if (isQian) System.out.println("公元前 " + myDate + "年,干支纪年是:" + tianganQ[tian] + dizhiQ[di]);// 公元前 } }
时间: 2024-10-07 05:22:39