easter_date() - 得到指定年份的复活节午夜时的Unix时间戳 - php 日历函数
easter_date()
(PHP 4, PHP 5, PHP 7)
得到指定年份的复活节午夜时的Unix时间戳。
说明
easter_date([int $year]): int返回指定年份的复活节午夜时的Unix时间戳。
Warning如果给定的年份超出Unix时间戳的范围(比如1970年以前或2037年以后),该函数将返回一个警告。
复活节的日期是由尼西亚议会在AD325年确定的为每年春分月圆后的第一个星期日。春分一般是在3月21日,这就简化为只要计算满月的日期和紧挨的星期日的日期。这里所用的算法是在532年由Dionysius Exiguus所介绍的,参考了Julian历法和Gregorian历法这两个历法来提高精确度。(在1753年以前用Julian历法计算,该历法是一个以19年为周期来确定月亮的相位的历法。在1753年以后用Gregorian历法计算,该历法由Clavius和Lilius发明,由Pope Gregory 8世在1582年推广)
参数
$year1970年至2037年之间的数字形式的年份。
返回值
复活节日期的Unix时间戳。
更新日志
版本 | 说明 |
---|---|
Since 4.3.0 | $year参数可选,缺省的默认值是当年。 |
范例
easter_date() example
参见
easter_days()
得到指定年份的3月21日到复活节之间的天数 for calculating Easter before 1970 or after 2037
To compute the correct Easter date for Eastern Orthodox Churches I made a function based on the Meeus Julian algorithm:
I recently had to write a function that allows me to know if today is a holiday. And in France, we have some holidays which depends on the easter date. Maybe this will be helpful to someone. Just modify in the $holidays array the actual holidays dates of your country.
Hey, recently I needed a function to get realization dates in online shop, so here it is (ready to go for polish users, please adjust your dates for any other country):
I found a problem with holidays timestamp computation and daylight saving time. An article about it at http://goo.gl/76t31 (in french only, sorry). In summary, this year (2013) easter begins before adding an hour for daylight saving time (occured sunday at 3:00). It means that if you do $easter + X, where x is a number of seconds equivalent to one day, 39 days or 50 days, the result is not equals to a midnight timestamp... Here a function to check if a midnight timestamp is equals to an holiday : function isHoliday( $ts ) { // Licence : Creative Commons (BY) // By Webpulser - http://goo.gl/76t31 $fixed_holidays = array( ’01-01′, ’01-05′, ’08-05′, ’14-07′, ’15-08′, ’11-11′, ’25-12′ ); $format = ‘d-m’; $dm = date($format, $ts); if ( in_array($dm, $fixed_holidays) ) return true; $easter = easter_date( date(‘Y’, $ts) ); if ( date($format, $easter + 86400) == $dm ) return true; if ( date($format, $easter + 3369600) == $dm ) return true; if ( date($format, $easter + 4320000) == $dm ) return true; return false; } feel free to use / modify.
Thank you, @Maxie, for algorythm for computing Orthodox Easter date. It can be improved though. You added 13 days in order to map Julian calendar to Gregorian. But 13 days is not a constant. It's an accumulated error fixed in Gregorian and should be calculated with this formula: (int)($year / 100) - (int)($year / 400) - 2
The algorithm from Bigtree is correct if you add some (int) cast
内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)