package com.ygj.yuemum.utils; public class IDcard { private final static int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23, 23, 23, 24, 23, 22 }; private final static String[] constellationArr = new String[] { "10", "11", "12", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10" }; /** * 根据出生日期计算属相和星座 * * @param */ // public static void main(String[] args) throws Exception{ // String idcardt ="130202198307080017"; // System.out.println(idcardt.length()); // String year = idcardt.substring(6,10); // String month = idcardt.substring(10,12); // String day = idcardt.substring(12,14); // String city =idcardt.substring(0,3)+"000"; // String province = idcardt.substring(0,6); // System.out.println("省份为:"+province); // System.out.println("城市为:"+city); // System.out.println("星座为:" + getConstellation(Integer.valueOf(month), Integer.valueOf(day))); // System.out.println("属相为:" + getYear(Integer.valueOf(year))); // } public String getidcard(String idcard){ String id; String res = ""; int month = 1; int day = 1; int year = 1981; res = "constellation: "+getConstellation(month, day)+","; res = res+"zodiac: "+getYear(year)+","; return res; } /** * Java通过生日计算星座 * * @param month * @param day * @return */ public static String getConstellation(int month, int day) { return day < dayArr[month - 1] ? constellationArr[month - 1] : constellationArr[month]; } /** * 通过生日计算属相 * * @param year * @return */ public static String getYear(int year) { if (year < 1900) { return "未知"; } int start = 1900; String[] years = new String[] { "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12" }; return years[(year - start) % years.length]; } }