php获取二十四节气,php判断某一天是否是某个节气,代码如下:
/** * @param int $time * @return mixed|string */ function getJieQi($time = 0) { date_default_timezone_set('Asia/Shanghai'); !$time && $time = time(); list($year, $month, $day) = explode('-', date('Y-m-d', $time)); $solar_term = [ 0 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1901 1 => [621, 519, 621, 621, 622, 722, 824, 824, 824, 924, 823, 823], //1902 2 => [621, 520, 722, 621, 722, 722, 824, 924, 924, 924, 823, 823], //1903 3 => [721, 520, 621, 520, 621, 622, 723, 823, 823, 824, 823, 722], //1904 4 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1905 5 => [621, 519, 621, 621, 622, 622, 824, 824, 824, 924, 823, 823], //1906 6 => [621, 520, 722, 621, 722, 722, 824, 924, 924, 924, 823, 823], //1907 7 => [721, 520, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //1908 8 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1909 9 => [621, 519, 621, 621, 622, 622, 824, 824, 824, 924, 823, 823], //1910 10 => [621, 520, 722, 621, 722, 722, 824, 924, 924, 924, 823, 823], //1911 11 => [721, 520, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //1912 12 => [620, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1913 13 => [621, 419, 621, 521, 622, 622, 824, 824, 824, 924, 823, 823], //1914 14 => [621, 520, 622, 621, 622, 722, 824, 824, 924, 924, 823, 823], //1915 15 => [621, 520, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722], //1916 16 => [620, 419, 621, 521, 621, 622, 823, 824, 823, 924, 823, 722], //1917 17 => [621, 419, 621, 521, 622, 622, 824, 824, 824, 924, 823, 822], //1918 18 => [621, 520, 622, 621, 622, 722, 824, 824, 924, 924, 823, 823], //1919 19 => [621, 520, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722], //1920 20 => [620, 419, 621, 520, 621, 622, 823, 824, 823, 924, 823, 722], //1921 21 => [621, 419, 621, 521, 622, 622, 824, 824, 824, 924, 823, 822], //1922 22 => [621, 519, 621, 621, 622, 722, 824, 824, 924, 924, 823, 823], //1923 23 => [621, 520, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722], //1924 24 => [620, 419, 621, 520, 621, 622, 823, 824, 823, 924, 823, 722], //1925 25 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1926 26 => [621, 519, 621, 621, 622, 722, 824, 824, 824, 924, 823, 823], //1927 27 => [621, 520, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //1928 28 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722], //1929 29 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1930 30 => [621, 519, 621, 621, 622, 722, 824, 824, 824, 924, 823, 823], //1931 31 => [621, 520, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //1932 32 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //1933 33 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1934 34 => [621, 519, 621, 621, 622, 622, 824, 824, 824, 924, 823, 823], //1935 35 => [621, 520, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //1936 36 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //1937 37 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1938 38 => [621, 519, 621, 621, 622, 622, 824, 824, 824, 924, 823, 823], //1939 39 => [621, 520, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //1940 40 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //1941 41 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1942 42 => [621, 519, 621, 621, 622, 622, 824, 824, 824, 924, 823, 823], //1943 43 => [621, 520, 621, 520, 521, 621, 723, 823, 823, 823, 722, 722], //1944 44 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722], //1945 45 => [620, 419, 621, 521, 622, 622, 823, 824, 823, 924, 823, 822], //1946 46 => [621, 419, 621, 521, 622, 622, 824, 824, 824, 924, 823, 823], //1947 47 => [621, 520, 521, 520, 521, 621, 723, 723, 823, 823, 722, 722], //1948 48 => [520, 419, 621, 520, 621, 622, 723, 824, 823, 824, 822, 722], //1949 49 => [620, 419, 621, 520, 621, 622, 823, 824, 823, 924, 823, 822], //1950 50 => [621, 419, 621, 521, 622, 622, 824, 824, 824, 924, 823, 823], //1951 51 => [621, 520, 521, 520, 521, 621, 723, 723, 823, 823, 722, 722], //1952 52 => [520, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722], //1953 53 => [620, 419, 621, 520, 621, 622, 823, 824, 823, 923, 823, 722], //1954 54 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1955 55 => [621, 520, 520, 520, 521, 621, 723, 723, 823, 823, 722, 722], //1956 56 => [520, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722], //1957 57 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //1958 58 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1958 59 => [621, 519, 520, 520, 521, 621, 723, 723, 723, 823, 722, 722], //1960 60 => [520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //1961 61 => [621, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //1962 62 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1963 63 => [621, 519, 520, 520, 521, 621, 723, 723, 723, 823, 722, 722], //1964 64 => [520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //1965 65 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //1966 66 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1967 67 => [621, 519, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722], //1968 68 => [520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //1969 69 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //1970 70 => [621, 419, 621, 521, 622, 622, 823, 824, 824, 924, 823, 822], //1971 71 => [621, 519, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722], //1972 72 => [520, 420, 621, 520, 521, 621, 723, 823, 823, 823, 722, 722], //1973 73 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //1974 74 => [621, 419, 621, 521, 622, 622, 823, 824, 823, 924, 823, 822], //1975 75 => [621, 519, 520, 420, 521, 521, 723, 724, 723, 823, 722, 722], //1976 76 => [520, 419, 621, 520, 621, 621, 723, 723, 823, 823, 722, 722], //1977 77 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 823, 722], //1978 78 => [621, 419, 621, 521, 621, 622, 823, 824, 823, 924, 823, 822], //1979 79 => [621, 519, 520, 420, 521, 521, 723, 723, 723, 823, 722, 722], //1980 80 => [520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 822, 722], //1981 81 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722], //1982 82 => [620, 419, 621, 520, 621, 622, 823, 824, 823, 924, 823, 822], //1983 83 => [621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 722], //1984 84 => [520, 419, 521, 520, 521, 621, 723, 723, 823, 823, 722, 722], //1985 85 => [520, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722], //1986 86 => [620, 419, 621, 520, 621, 622, 723, 824, 823, 924, 823, 722], //1987 87 => [621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721], //1988 88 => [520, 419, 520, 520, 521, 621, 723, 723, 723, 823, 722, 722], //1989 89 => [520, 419, 621, 520, 621, 621, 723, 823, 823, 824, 822, 722], //1990 90 => [620, 419, 621, 520, 721, 622, 723, 823, 823, 924, 823, 722], //1991 91 => [621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721], //1992 92 => [520, 418, 520, 520, 521, 621, 723, 723, 723, 823, 722, 722], //1993 93 => [520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //1994 94 => [620, 419, 621, 520, 621, 622, 723, 821, 823, 924, 823, 722], //1995 95 => [621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721], //1996 96 => [520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722], //1997 97 => [520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //1998 98 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //1999 99 => [621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721], //2000 100 => [520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722], //2001 101 => [520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //2002 102 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //2003 103 => [621, 419, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721], //2004 104 => [520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722], //2005 105 => [520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722], //2006 106 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 924, 823, 722], //2007 107 => [621, 419, 520, 420, 521, 521, 722, 723, 722, 823, 722, 721], //2008 108 => [520, 418, 520, 420, 521, 521, 723, 723, 723, 823, 722, 722], //2009 109 => [520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722], //2010 110 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 823, 722], //2011 111 => [621, 419, 520, 420, 520, 521, 722, 723, 722, 823, 722, 721], //2012 112 => [520, 418, 520, 420, 521, 521, 722, 723, 723, 823, 722, 722], //2013 113 => [520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722], //2014 114 => [620, 419, 621, 520, 621, 622, 723, 823, 823, 824, 822, 722], //2015 115 => [620, 419, 520, 419, 520, 521, 722, 723, 722, 823, 722, 721], //2016 116 => [520, 318, 520, 420, 521, 521, 722, 723, 723, 823, 722, 722], //2017 117 => [520, 419, 521, 520, 521, 621, 723, 723, 823, 823, 722, 722], //2018 118 => [520, 419, 621, 520, 621, 621, 723, 823, 823, 824, 822, 722], //2019 119 => [620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 721], //2020 120 => [520, 318, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721], //2021 121 => [520, 419, 520, 520, 521, 621, 723, 723, 723, 823, 722, 722], //2022 122 => [520, 419, 621, 520, 621, 621, 723, 823, 823, 824, 822, 722], //2023 123 => [620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 621], //2024 124 => [520, 318, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721], //2025 125 => [520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722], //2026 126 => [520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //2027 127 => [620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 621], //2028 128 => [520, 318, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721], //2029 129 => [520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722], //2030 130 => [520, 419, 621, 520, 621, 621, 723, 823, 823, 823, 722, 722], //2031 131 => [620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 621], //2032 132 => [520, 318, 520, 420, 521, 521, 723, 723, 723, 823, 722, 721], //2033 133 => [520, 418, 520, 520, 521, 521, 723, 823, 723, 823, 722, 722], //2034 134 => [520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722], //2035 135 => [620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 621], //2036 136 => [520, 318, 520, 420, 521, 521, 722, 723, 723, 823, 722, 721], //2037 137 => [520, 418, 520, 520, 521, 521, 723, 723, 723, 823, 722, 722], //2038 138 => [520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722], //2039 139 => [620, 419, 520, 419, 520, 521, 622, 722, 722, 823, 722, 621], //2040 140 => [520, 318, 520, 420, 520, 521, 722, 723, 722, 823, 722, 721], //2041 141 => [520, 418, 520, 420, 521, 521, 723, 723, 723, 823, 722, 722], //2042 142 => [520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722], //2043 143 => [620, 419, 520, 419, 520, 521, 622, 722, 722, 723, 722, 621], //2044 144 => [520, 318, 520, 419, 520, 521, 722, 723, 722, 823, 722, 721], //2045 145 => [520, 418, 520, 420, 521, 521, 722, 723, 723, 823, 722, 722], //2046 146 => [520, 419, 621, 520, 521, 621, 723, 723, 823, 823, 722, 722], //2047 147 => [620, 419, 520, 419, 520, 520, 622, 722, 722, 723, 721, 621], //2048 148 => [519, 318, 520, 520, 520, 521, 622, 722, 722, 823, 722, 721], //2049 149 => [520, 318, 520, 420, 521, 521, 722, 723, 823, 823, 722, 722] //2050 ]; //节气名称 $term_name = [ '小寒', '大寒', '立春', '雨水', '惊蛰', '春分', '清明', '谷雨', '立夏', '小满', '芒种', '夏至', '小暑', '大暑', '立秋', '处暑', '白露', '秋分', '寒露', '霜降', '立冬', '小雪', '大雪', '冬至']; //算取在数组中的位置 $line = $year - 1901; $row = $month - 1; //显示相应的节气 if ($day == substr($solar_term[$line][$row], 0, 1)) { $term = $term_name[($month - 1) * 2]; } else if ($day == substr($solar_term[$line][$row], 1, 2)) { $term = $term_name[($month - 1) * 2 + 1]; } else {//from php.hhsy.cc $term = ''; } return $term; }
示例:
echo getJieQi(1584652027);//春分