日期匹配星座,月日匹配星座,android 星座
【摘要】
通过 月日实现匹配星座功能 先准备数据
Android 版本数据
我是用的 array 这个可以直接拷贝到项目中直接用
<pre name="code" class="java"><string name="constellation_aries">白羊座<...
通过 月日实现匹配星座功能 先准备数据
Android 版本数据
我是用的 array 这个可以直接拷贝到项目中直接用
-
<pre name="code" class="java"><string name="constellation_aries">白羊座</string>
-
<string name="constellation_taurus">金牛座</string>
-
<string name="constellation_gemini">双子座</string>
-
<string name="constellation_cancer">巨蟹座</string>
-
<string name="constellation_leo">狮子座</string>
-
<string name="constellation_virgo">处女座</string>
-
<string name="constellation_libra">天秤座</string>
-
<string name="constellation_scorpio">天蝎座</string>
-
<string name="constellation_sagittarius">射手座</string>
-
<string name="constellation_capricorn">摩羯座</string>
-
<string name="constellation_aquarius">水瓶座</string>
-
<string name="constellation_pisces">双鱼座</string>
-
-
<string-array name="user_constellation">
-
<item>@string/constellation_aries</item>
-
<item>@string/constellation_taurus</item>
-
<item>@string/constellation_gemini</item>
-
<item>@string/constellation_cancer</item>
-
<item>@string/constellation_leo</item>
-
<item>@string/constellation_virgo</item>
-
<item>@string/constellation_libra</item>
-
<item>@string/constellation_scorpio</item>
-
<item>@string/constellation_sagittarius</item>
-
<item>@string/constellation_capricorn</item>
-
<item>@string/constellation_aquarius</item>
-
<item>@string/constellation_pisces</item>
-
</string-array>
-
-
String constellation = DateTimeUtil.getConstellation(getResources().getStringArray(R.array.user_constellation),month,day);
-
-
-
-
java版本数据
-
public static final String[] contellationArr = {"水瓶座","双鱼座","白羊座","金牛座","双子座","巨蟹座","狮子座","处女座","天秤座","天蝎座","射手座","魔羯座"};
-
-
-
//contellationArr 星座的数组
-
//month 月份
-
//day 日
-
-
public static String getConstellation(String [] contellationArr,int month,int day){
-
int point = -1;
-
Double date = Double.parseDouble(month + "." + day);
-
if (3.21 <= date && 4.19 >= date) {
-
point = 0;
-
} else if (4.20 <= date && 5.20 >= date) {
-
point = 1;
-
} else if (5.21 <= date && 6.21 >= date) {
-
point = 2;
-
} else if (6.22 <= date && 7.22 >= date) {
-
point = 3;
-
} else if (7.23 <= date && 8.22 >= date) {
-
point = 4;
-
} else if (8.23 <= date && 9.22 >= date) {
-
point = 5;
-
} else if (9.23 <= date && 10.23 >= date) {
-
point = 6;
-
} else if (10.24 <= date && 11.22 >= date) {
-
point = 7;
-
} else if (11.23 <= date && 12.21 >= date) {
-
point = 8;
-
} else if (12.22 <= date && 12.31 >= date) {
-
point = 9;
-
} else if (1.01 <= date && 1.19 >= date) {
-
point = 9;
-
} else if (1.20 <= date && 2.18 >= date) {
-
point = 10;
-
} else if (2.19 <= date && 3.20 >= date) {
-
point = 11;
-
}
-
if(point == -1) {
-
return contellationArr[2];
-
}
-
return contellationArr[point];
-
}
附 :星座月份对照图一张
欢迎大家加入 android开发经验交流群:454430053
文章来源: wukong.blog.csdn.net,作者:再见孙悟空_,版权归原作者所有,如需转载,请联系作者。
原文链接:wukong.blog.csdn.net/article/details/50899141
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)