logo
当前位置:首 页 > 编程技术 >后端开发 >PHP语言 > 查看文章

都是晚上找的,不知道是哪位大神写的

隔空夸奖下

 

这套代码测试了,目前是准确的

 

  1. /**
  2.   *
  3.   * 二十四节气通用的新算法
  4.   *
  5.   *
  6.   *
  7.   *
  8.   * */
  9.  
  10.  
  11. function solar_term($years,$mon,$mday)
  12. {
  13. $solar_term = array(
  14. 0=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1901
  15. 1=>array(621, 519, 621, 621, 622, 722, 824, 824, 824, 924, 823, 823), //1902
  16. 2=>array(621, 520, 722, 621, 722, 722, 824, 924, 924, 924, 823, 823), //1903
  17. 3=>array(721, 520, 621, 520, 621, 622, 723, 823, 823, 824, 823, 722), //1904
  18. 4=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1905
  19. 5=>array(621, 519, 621, 621, 622, 622, 824, 824, 824, 924, 823, 823), //1906
  20. 6=>array(621, 520, 722, 621, 722, 722, 824, 924, 924, 924, 823, 823), //1907
  21. 7=>array(721, 520, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //1908
  22. 8=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1909
  23. 9=>array(621, 519, 621, 621, 622, 622, 824, 824, 824, 924, 823, 823), //1910
  24. 10=>array(621, 520, 722, 621, 722, 722, 824, 924, 924, 924, 823, 823), //1911
  25. 11=>array(721, 520, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //1912
  26. 12=>array(620, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1913
  27. 13=>array(621, 419, 621, 521, 622, 622, 824, 824, 824, 924, 823, 823), //1914
  28. 14=>array(621, 520, 622, 621, 622, 722, 824, 824, 924, 924, 823, 823), //1915
  29. 15=>array(621, 520, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722), //1916
  30. 16=>array(620, 419, 621, 521, 621, 622, 823, 824, 823, 924, 823, 722), //1917
  31. 17=>array(621, 419, 621, 521, 622, 622, 824, 824, 824, 924, 823, 822), //1918
  32. 18=>array(621, 520, 622, 621, 622, 722, 824, 824, 924, 924, 823, 823), //1919
  33. 19=>array(621, 520, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722), //1920
  34. 20=>array(620, 419, 621, 520, 621, 622, 823, 824, 823, 924, 823, 722), //1921
  35. 21=>array(621, 419, 621, 521, 622, 622, 824, 824, 824, 924, 823, 822), //1922
  36. 22=>array(621, 519, 621, 621, 622, 722, 824, 824, 924, 924, 823, 823), //1923
  37. 23=>array(621, 520, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722), //1924
  38. 24=>array(620, 419, 621, 520, 621, 622, 823, 824, 823, 924, 823, 722), //1925
  39. 25=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1926
  40. 26=>array(621, 519, 621, 621, 622, 722, 824, 824, 824, 924, 823, 823), //1927
  41. 27=>array(621, 520, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //1928
  42. 28=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722), //1929
  43. 29=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1930
  44. 30=>array(621, 519, 621, 621, 622, 722, 824, 824, 824, 924, 823, 823), //1931
  45. 31=>array(621, 520, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //1932
  46. 32=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //1933
  47. 33=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1934
  48. 34=>array(621, 519, 621, 621, 622, 622, 824, 824, 824, 924, 823, 823), //1935
  49. 35=>array(621, 520, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //1936
  50. 36=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //1937
  51. 37=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1938
  52. 38=>array(621, 519, 621, 621, 622, 622, 824, 824, 824, 924, 823, 823), //1939
  53. 39=>array(621, 520, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //1940
  54. 40=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //1941
  55. 41=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1942
  56. 42=>array(621, 519, 621, 621, 622, 622, 824, 824, 824, 924, 823, 823), //1943
  57. 43=>array(621, 520, 621, 520, 521, 621, 723, 823, 823, 823, 722, 722), //1944
  58. 44=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722), //1945
  59. 45=>array(620, 419, 621, 521, 622, 622, 823, 824, 823, 924, 823, 822), //1946
  60. 46=>array(621, 419, 621, 521, 622, 622, 824, 824, 824, 924, 823, 823), //1947
  61. 47=>array(621, 520, 521, 520, 521, 621, 723, 723, 823, 823, 722, 722), //1948
  62. 48=>array(520, 419, 621, 520, 621, 622, 723, 824, 823, 824, 822, 722), //1949
  63. 49=>array(620, 419, 621, 520, 621, 622, 823, 824, 823, 924, 823, 822), //1950
  64. 50=>array(621, 419, 621, 521, 622, 622, 824, 824, 824, 924, 823, 823), //1951
  65. 51=>array(621, 520, 521, 520, 521, 621, 723, 723, 823, 823, 722, 722), //1952
  66. 52=>array(520, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722), //1953
  67. 53=>array(620, 419, 621, 520, 621, 622, 823, 824, 823, 923, 823, 722), //1954
  68. 54=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1955
  69. 55=>array(621, 520, 520, 520, 521, 621, 723, 723, 823, 823, 722, 722), //1956
  70. 56=>array(520, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722), //1957
  71. 57=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //1958
  72. 58=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1958
  73. 59=>array(621, 519, 520, 520, 521, 621, 723, 723, 723, 823, 722, 722), //1960
  74. 60=>array(520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //1961
  75. 61=>array(621, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //1962
  76. 62=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1963
  77. 63=>array(621, 519, 520, 520, 521, 621, 723, 723, 723, 823, 722, 722), //1964
  78. 64=>array(520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //1965
  79. 65=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //1966
  80. 66=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1967
  81. 67=>array(621, 519, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722), //1968
  82. 68=>array(520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //1969
  83. 69=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //1970
  84. 70=>array(621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822), //1971
  85. 71=>array(621, 519, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722), //1972
  86. 72=>array(520, 420, 621, 520, 521, 621, 723, 823, 823, 823, 722, 722), //1973
  87. 73=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //1974
  88. 74=>array(621, 419, 621, 521, 622, 622, 823, 824, 823, 924, 823, 822), //1975
  89. 75=>array(621, 519, 520, 420, 521, 521, 723, 724, 723, 823, 722, 722), //1976
  90. 76=>array(520, 419, 621, 520, 621, 621, 723, 723, 823, 823, 722, 722), //1977
  91. 77=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 823, 722), //1978
  92. 78=>array(621, 419, 621, 521, 621, 622, 823, 824, 823, 924, 823, 822), //1979
  93. 79=>array(621, 519, 520, 420, 521, 521, 723, 723, 723, 823, 722, 722), //1980
  94. 80=>array(520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 822, 722), //1981
  95. 81=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722), //1982
  96. 82=>array(620, 419, 621, 520, 621, 622, 823, 824, 823, 924, 823, 822), //1983
  97. 83=>array(621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 722), //1984
  98. 84=>array(520, 419, 521, 520, 521, 621, 723, 723, 823, 823, 722, 722), //1985
  99. 85=>array(520, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722), //1986
  100. 86=>array(620, 419, 621, 520, 621, 622, 723, 824, 823, 924, 823, 722), //1987
  101. 87=>array(621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721), //1988
  102. 88=>array(520, 419, 520, 520, 521, 621, 723, 723, 723, 823, 722, 722), //1989
  103. 89=>array(520, 419, 621, 520, 621, 621, 723, 823, 823, 824, 822, 722), //1990
  104. 90=>array(620, 419, 621, 520, 721, 622, 723, 823, 823, 924, 823, 722), //1991
  105. 91=>array(621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721), //1992
  106. 92=>array(520, 418, 520, 520, 521, 621, 723, 723, 723, 823, 722, 722), //1993
  107. 93=>array(520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //1994
  108. 94=>array(620, 419, 621, 520, 621, 622, 723, 821, 823, 924, 823, 722), //1995
  109. 95=>array(621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721), //1996
  110. 96=>array(520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722), //1997
  111. 97=>array(520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //1998
  112. 98=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //1999
  113. 99=>array(621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721), //2000
  114. 100=>array(520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722), //2001
  115. 101=>array(520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //2002
  116. 102=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //2003
  117. 103=>array(621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721), //2004
  118. 104=>array(520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722), //2005
  119. 105=>array(520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722), //2006
  120. 106=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722), //2007
  121. 107=>array(621, 419, 520, 420, 521, 521, 722, 723, 722, 823, 722, 721), //2008
  122. 108=>array(520, 418, 520, 420, 521, 521, 723, 723, 723, 823, 722, 722), //2009
  123. 109=>array(520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722), //2010
  124. 110=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 823, 722), //2011
  125. 111=>array(621, 419, 520, 420, 520, 521, 722, 723, 722, 823, 722, 721), //2012
  126. 112=>array(520, 418, 520, 420, 521, 521, 722, 723, 723, 823, 722, 722), //2013
  127. 113=>array(520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722), //2014
  128. 114=>array(620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722), //2015
  129. 115=>array(620, 419, 520, 419, 520, 521, 722, 723, 722, 823, 722, 721), //2016
  130. 116=>array(520, 318, 520, 420, 521, 521, 722, 723, 723, 823, 722, 722), //2017
  131. 117=>array(520, 419, 521, 520, 521, 621, 723, 723, 823, 823, 722, 722), //2018
  132. 118=>array(520, 419, 621, 520, 621, 621, 723, 823, 823, 824, 822, 722), //2019
  133. 119=>array(620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 721), //2020
  134. 120=>array(520, 318, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721), //2021
  135. 121=>array(520, 419, 520, 520, 521, 621, 723, 723, 723, 823, 722, 722), //2022
  136. 122=>array(520, 419, 621, 520, 621, 621, 723, 823, 823, 824, 822, 722), //2023
  137. 123=>array(620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 621), //2024
  138. 124=>array(520, 318, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721), //2025
  139. 125=>array(520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722), //2026
  140. 126=>array(520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //2027
  141. 127=>array(620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 621), //2028
  142. 128=>array(520, 318, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721), //2029
  143. 129=>array(520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722), //2030
  144. 130=>array(520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722), //2031
  145. 131=>array(620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 621), //2032
  146. 132=>array(520, 318, 520, 420, 521, 521, 723, 723, 723, 823, 722, 721), //2033
  147. 133=>array(520, 418, 520, 520, 521, 521, 723, 823, 723, 823, 722, 722), //2034
  148. 134=>array(520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722), //2035
  149. 135=>array(620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 621), //2036
  150. 136=>array(520, 318, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721), //2037
  151. 137=>array(520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722), //2038
  152. 138=>array(520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722), //2039
  153. 139=>array(620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 621), //2040
  154. 140=>array(520, 318, 520, 420, 520, 521, 722, 723, 722, 823, 722, 721), //2041
  155. 141=>array(520, 418, 520, 420, 521, 521, 723, 723, 723, 823, 722, 722), //2042
  156. 142=>array(520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722), //2043
  157. 143=>array(620, 419, 520, 419, 520, 521, 622, 722, 722, 723, 722, 621), //2044
  158. 144=>array(520, 318, 520, 419, 520, 521, 722, 723, 722, 823, 722, 721), //2045
  159. 145=>array(520, 418, 520, 420, 521, 521, 722, 723, 723, 823, 722, 722), //2046
  160. 146=>array(520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722), //2047
  161. 147=>array(620, 419, 520, 419, 520, 520, 622, 722, 722, 723, 721, 621), //2048
  162. 148=>array(519, 318, 520, 520, 520, 521, 622, 722, 722, 823, 722, 721), //2049
  163. 149=>array(520, 318, 520, 420, 521, 521, 722, 723, 823, 823, 722, 722) //2050
  164. );
  165. //节气名称
  166. $term_name = array(
  167. "小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨",
  168. "立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑",
  169. "白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至");
  170.  
  171. //获取当前日期及其年月日
  172. // $today = getdate();
  173. $this_year = $years;
  174. $this_month = $mon;
  175. $this_day = $mday;
  176.  
  177. //算取在数组中的位置
  178. $line = $this_year-1901;
  179. $row = $this_month-1;
  180.  
  181. //获取数组中的两个日期
  182. $term_one =substr($solar_term[$line][$row], 0, 1);
  183. $term_two =substr($solar_term[$line][$row], 1, 2);
  184.  
  185. //获取在节气表中的位置
  186. $t_name_1 = ($this_month-1)*2;
  187. $t_name_2 = ($this_month-1)*2+1;
  188.  
  189. //显示相应的节气
  190. if ($this_day==$term_one)
  191. {
  192. $this_term = $term_name[$t_name_1];
  193. }
  194. else if($this_day==$term_two)
  195. {
  196. $this_term = $term_name[$t_name_2];
  197. }
  198. else
  199. {
  200. $this_term = NULL;
  201. }
  202. return $this_term;
  203. }

 

这套代码测试了一直不准

 

  1. /*
  2.   * 节气通用算法
  3.   */
  4. function getJieQi($_year, $month, $day)
  5. {
  6. $year = substr($_year, -2) + 0;
  7. $coefficient = array(
  8. array(5.4055, 2019, -1),//小寒
  9. array(20.12, 2082, 1),//大寒
  10. array(3.87),//立春
  11. array(18.74, 2026, -1),//雨水
  12. array(5.63),//惊蛰
  13. array(20.646, 2084, 1),//春分
  14. array(4.81),//清明
  15. array(20.1),//谷雨
  16. array(5.52, 1911, 1),//立夏
  17. array(21.04, 2008, 1),//小满
  18. array(5.678, 1902, 1),//芒种
  19. array(21.37, 1928, 1),//夏至
  20. array(7.108, 2016, 1),//小暑
  21. array(22.83, 1922, 1),//大暑
  22. array(7.5, 2002, 1),//立秋
  23. array(23.13),//处暑
  24. array(7.646, 1927, 1),//白露
  25. array(23.042, 1942, 1),//秋分
  26. array(8.318),//寒露
  27. array(23.438, 2089, 1),//霜降
  28. array(7.438, 2089, 1),//立冬
  29. array(22.36, 1978, 1),//小雪
  30. array(7.18, 1954, 1),//大雪
  31. array(21.94, 2021, -1)//冬至
  32. );
  33. $term_name = array(
  34. "小寒", "大寒", "立春", "雨水", "惊蛰", "春分", "清明", "谷雨",
  35. "立夏", "小满", "芒种", "夏至", "小暑", "大暑", "立秋", "处暑",
  36. "白露", "秋分", "寒露", "霜降", "立冬", "小雪", "大雪", "冬至");
  37.  
  38. $idx1 = ($month - 1) * 2;
  39. $_leap_value = floor(($year - 1) / 4);
  40. $day1 = floor($year * 0.2422 + $coefficient[$idx1][0]) - $_leap_value;
  41. if (isset($coefficient[$idx1][1]) && $coefficient[$idx1][1] == $_year) $day1 += $coefficient[$idx1][2];
  42. $day2 = floor($year * 0.2422 + $coefficient[$idx1 + 1][0]) - $_leap_value;
  43. if (isset($coefficient[$idx1 + 1][1]) && $coefficient[$idx1 + 1][1] == $_year) $day1 += $coefficient[$idx1 + 1][2];
  44.  
  45. //echo __FILE__.'->'.__LINE__.' $day1='.$day1,',$day2='.$day2.'<br/>'.chr(10);
  46. $data = array();
  47.  
  48. if ($day < $day1) {
  49.  
  50. $data['name1'] = $term_name[$idx1 - 1];
  51. $data['name2'] = $term_name[$idx1 - 1] . '后';
  52. } else if ($day == $day1) {
  53. $data['name1'] = $term_name[$idx1];
  54. $data['name2'] = $term_name[$idx1];
  55. } else if ($day > $day1 && $day < $day2) {
  56.  
  57.  
  58. $data['name1'] = $term_name[$idx1];
  59. $data['name2'] = $term_name[$idx1] . '后';
  60. } else if ($day == $day2) {
  61. $data['name1'] = $term_name[$idx1 + 1];
  62. $data['name2'] = $term_name[$idx1 + 1];
  63. } else if ($day > $day2) {
  64. $data['name1'] = $term_name[$idx1 + 1];
  65. $data['name2'] = $term_name[$idx1 + 1] . '后';
  66. }
  67. return $data;
  68. }

 

说说梦想,谈谈感悟 ,聊聊技术,有啥要说的来github留言吧 https://github.com/cjx2328

—— 陈 建鑫

陈建鑫
footer logo
未经许可请勿自行使用、转载、修改、复制、发行、出售、发表或以其它方式利用本网站之内容。站长联系:cjx2328#126.com(修改#为@)
Copyright ©ziao Studio All Rights Reserved. E-mail:cjx2328#126.com(#号改成@) 沪ICP备14052271号-3