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

How to calculate horoscope from date

不言
不言Original
2018-07-07 10:58:432064browse

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 = [摩羯,水瓶, 双鱼,白羊,金牛,双子,巨蟹,狮子,处女,天秤,天蝎,射手,摩羯]

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来获取“当前天气信息”

Start Month #ConstellationEnding month#Time interval
1222Capricorn11912/22 - 1/19
120Aquarius2181/ 20 - 2/18
219Pisces3202/19 - 3/20

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!

Statement:
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