| 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
 | | package com.matrix.system.hive.plugin.util; |  |   |  | import java.util.Calendar; |  | import java.util.Date; |  |   |  | /** |  |  * 通过生日获取生肖和星座 |  |  *  |  |  * @author jyy |  |  * @createTime 2016.08.18 |  |  */ |  | public class BirthdayUtils { |  |   |  |      |  |     public static final String[] zodiacArr = { "猴", "鸡", "狗", "猪", "鼠", "牛", "虎", "兔", "龙", "蛇", "马", "羊" }; |  |       |  |     public static final String[] constellationArr = { "水瓶座", "双鱼座", "白羊座", "金牛座", "双子座", "巨蟹座", "狮子座", "处女座", "天秤座", "天蝎座", "射手座", "魔羯座" }; |  |       |  |     public static final int[] constellationEdgeDay = { 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22 }; |  |       |  |     /** |  |      * 根据日期获取生肖 |  |      * @return |  |      */ |  |     public static String getZodica(Date date) { |  |         Calendar cal = Calendar.getInstance(); |  |         cal.setTime(date); |  |         return zodiacArr[cal.get(Calendar.YEAR) % 12]; |  |     } |  |       |  |     /** |  |      * 根据日期获取星座 |  |      * @return |  |      */ |  |     public static String getConstellation(Date date) { |  |         if (date == null) { |  |             return ""; |  |         } |  |         Calendar cal = Calendar.getInstance(); |  |         cal.setTime(date); |  |         int month = cal.get(Calendar.MONTH); |  |         int day = cal.get(Calendar.DAY_OF_MONTH); |  |         if (day < constellationEdgeDay[month]) { |  |             month = month - 1; |  |         } |  |         if (month >= 0) { |  |             return constellationArr[month]; |  |         } |  |         // default to return 魔羯 |  |         return constellationArr[11]; |  |     } |  |      |  | } | 
 |