IDcard.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package com.ygj.yuemum.utils;
  2. public class IDcard {
  3. private final static int[] dayArr = new int[] { 20, 19, 21, 20, 21, 22, 23,
  4. 23, 23, 24, 23, 22 };
  5. private final static String[] constellationArr = new String[] { "10",
  6. "11", "12", "1", "2", "3", "4", "5", "6", "7",
  7. "8", "9", "10" };
  8. /**
  9. * 根据出生日期计算属相和星座
  10. *
  11. * @param
  12. */
  13. // public static void main(String[] args) throws Exception{
  14. // String idcardt ="130202198307080017";
  15. // System.out.println(idcardt.length());
  16. // String year = idcardt.substring(6,10);
  17. // String month = idcardt.substring(10,12);
  18. // String day = idcardt.substring(12,14);
  19. // String city =idcardt.substring(0,3)+"000";
  20. // String province = idcardt.substring(0,6);
  21. // System.out.println("省份为:"+province);
  22. // System.out.println("城市为:"+city);
  23. // System.out.println("星座为:" + getConstellation(Integer.valueOf(month), Integer.valueOf(day)));
  24. // System.out.println("属相为:" + getYear(Integer.valueOf(year)));
  25. // }
  26. public String getidcard(String idcard){
  27. String id;
  28. String res = "";
  29. int month = 1;
  30. int day = 1;
  31. int year = 1981;
  32. res = "constellation: "+getConstellation(month, day)+",";
  33. res = res+"zodiac: "+getYear(year)+",";
  34. return res;
  35. }
  36. /**
  37. * Java通过生日计算星座
  38. *
  39. * @param month
  40. * @param day
  41. * @return
  42. */
  43. public static String getConstellation(int month, int day) {
  44. return day < dayArr[month - 1] ? constellationArr[month - 1]
  45. : constellationArr[month];
  46. }
  47. /**
  48. * 通过生日计算属相
  49. *
  50. * @param year
  51. * @return
  52. */
  53. public static String getYear(int year) {
  54. if (year < 1900) {
  55. return "未知";
  56. }
  57. int start = 1900;
  58. String[] years = new String[] { "1", "2", "3", "4", "5", "6", "7", "8",
  59. "9", "10", "11", "12" };
  60. return years[(year - start) % years.length];
  61. }
  62. }