Home > Web Front-end > JS Tutorial > How to calculate horoscope from date

How to calculate horoscope from date

不言
Release: 2018-07-07 10:58:43
Original
2237 people have browsed it

This article mainly introduces the calculation of zodiac signs through dates, which has a certain reference value. Now I share it with everyone. Friends in need can refer to it

##321Aries420 3/22 - 4/20421Taurus5204/22 - 5/20521Gemini 6215/22 - 6/21622Cancer7226/22 - 7/22723Leo8227/22 - 8/22823Virgo9228/22 - 9/22923Libra10229/22 - 10/22 1023SCORPIO112110/22 - 11/211122Sagittarius122111/22 - 12/211222Capricorn11912/22 - 1/ 19##

12 months in a year
Abstract an array

c = [摩羯,水瓶, 双鱼,白羊,金牛,双子,巨蟹,狮子,处女,天秤,天蝎,射手,摩羯]
Copy after login

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]
Copy after login

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 < The starting month is the starting number of the zodiac sign corresponding to the month)
Example February 18th is Aquarius and February 19th is Gemini
18 < 19 (19 is Pisces in February Starting date) If less than true, 2 - 1 = 1. The corresponding zodiac sign for January is Aquarius
19 = 19. If less than true, 2 - 0 = 2, so the corresponding zodiac sign for February is Pisces

Simplified list Cancel the date list
day < Date[month] =》 day - x < Date[month] - x
Let y = Date[month] - x, y needs to be a single digit
From now on The minimum number corresponding to the start date is 19th (Pisces) and the maximum is 23rd (Leo)
Exhaustive and list the table

Start Month #Constellation Ending month #Time interval
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
##154√194√163√203##17##181√2210
x yx y = 19xyx y =23
109
149
118
158
127
167
136
176
145185

2212

##19
230##

两列中x的交集为 14 -19
取x = 14

Date = [22, 20, 19, 21, 21, 21, 22, 23, 23, 23, 23, 22, 22]
Copy after login

date - 14
最后列表为8,6,5,7,7,8,9,9,9,9,8,8 => '865778999988'

startMonth = month - [(day < Date[month]) ? 1 : 0]
=> month - (day - 14 < &#39;865778999988&#39;.charAt(month))  
true 自动变为 1;  
true 自动变为 0;  
charAt为寻找字符串对应位置的str
Copy after login

最终代码

var date = new Date(2017,1,12);
//设置日期
function getHoroscope(date) {
  var c = [&#39;摩羯&#39;,&#39;水瓶&#39;,&#39;双鱼&#39;,&#39;白羊&#39;,&#39;金牛&#39;,&#39;双子&#39;,&#39;巨蟹&#39;,&#39;狮子&#39;,&#39;处女&#39;,&#39;天秤&#39;,&#39;天蝎&#39;,&#39;射手&#39;,&#39;摩羯&#39;]
  var month = date.getMonth() + 1;
  var day = date.getDate();
  var startMonth = month - (day - 14 < &#39;865778999988&#39;.charAt(month));
  return c[startMonth]
}
getHoroscope(date);
//水瓶
Copy after login

以上就是本文的全部内容,希望对大家的学习有所帮助,更多相关内容请关注PHP中文网!

相关推荐:

js把页面的table标签导出为csv

原生JS和jQuery分别使用jsonp来获取“当前天气信息”

The above is the detailed content of How to calculate horoscope from date. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template