12 |
22 |
Capricorn |
1 |
19 |
12/22 - 1/19 |
1 |
20 |
Aquarius |
2 |
18 |
1/ 20 - 2/18 |
2 |
19 |
Pisces |
3 |
20 |
2/19 - 3/20 |
##3 | 21 | Aries | 4 | 20 | 3/22 - 4/20 |
4 | 21 | Taurus | 5 | 20 | 4/22 - 5/20 |
5 | 21 | Gemini | 6 | 21 | 5/22 - 6/21 |
6 | 22 | Cancer | 7 | 22 | 6/22 - 7/22 |
7 | 23 | Leo | 8 | 22 | 7/22 - 8/22 |
8 | 23 | Virgo | 9 | 22 | 8/22 - 9/22 |
9 | 23 | Libra | 10 | 22 | 9/22 - 10/22 |
10 | 23 | SCORPIO | 11 | 21 | 10/22 - 11/21 |
11 | 22 | Sagittarius | 12 | 21 | 11/22 - 12/21 |
12 | 22 | Capricorn | 1 | 19 | 12/22 - 1/ 19 |
##12 months in a year
Abstract an array
c = [摩羯,水瓶, 双鱼,白羊,金牛,双子,巨蟹,狮子,处女,天秤,天蝎,射手,摩羯]
c is a list of months
The starting month corresponding to the Aquarius with the serial number 1 in the array isJanuary
The serial number is Starting month or (Ending month - 1)
The constellation corresponding to the dateThe starting month is the date The month or the ending month is the month (that is, the starting month is the month -1 of the date)
In order to get the constellation corresponding to the date, we calculate the start of the corresponding constellation through the date Month
startMonth = month - [(day < Date[month]) ? 1 : 0]
c = [摩羯,水瓶, 双鱼,白羊,金牛,双子,巨蟹,狮子,处女,天秤,天蝎,射手,摩羯]
index = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
Date = [22, 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22]
startMonth - the calculated starting month of the corresponding constellation;
Month - the month corresponding to the date;
day - the number corresponding to the date;
Date - the date corresponding to the month list List;
Explanation:
Corresponding constellation starting month = current month - [(whether the current date is less than the date of the corresponding month), if yes, it is 1, otherwise it is 0]
Judge (date corresponding number Number a54aa723b94edbab5bbca5c06cea1a05 '865778999988'
startMonth = month - [(day < Date[month]) ? 1 : 0]
=> month - (day - 14 < '865778999988'.charAt(month))
true 自动变为 1;
true 自动变为 0;
charAt为寻找字符串对应位置的str
最终代码
var date = new Date(2017,1,12);
//设置日期
function getHoroscope(date) {
var c = ['摩羯','水瓶','双鱼','白羊','金牛','双子','巨蟹','狮子','处女','天秤','天蝎','射手','摩羯']
var month = date.getMonth() + 1;
var day = date.getDate();
var startMonth = month - (day - 14 < '865778999988'.charAt(month));
return c[startMonth]
}
getHoroscope(date);
//水瓶
以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!
相关推荐:
js把页面的table标签导出为csv
原生JS和jQuery分别使用jsonp来获取“当前天气信息”