PHP Calendar



PHP Calendar Introduction

The calendar extension contains functions that simplify conversion between different calendar formats.

It is based on the Julian Day Count, which began on January 1, 4713 BC.

Note:If you need to convert between calendar formats, you must first convert to Julian Day Count and then convert to the calendar format you need.

Note:Julian Day Count and Julian Calendar are not the same thing!


Installation

In order for these functions to work, you must compile PHP with --enable-calendar.

The Windows version of PHP has built-in support for calendar extensions. Therefore, the Calendar function works automatically.


PHP 5 Calendar function

Function Description
cal_days_in_month( ) Returns the number of days in a month for the specified year and calendar.
cal_from_jd() Converts the Julian day count to a date in the specified calendar.
cal_info() Returns information about the specified calendar.
cal_to_jd() Convert the date in the specified calendar to Julian day counting.
easter_date() Returns the Unix timestamp of Easter midnight in the specified year.
easter_days() Returns the number of days between Easter and March 21 in the specified year.
frenchtojd() Convert French Republican calendar dates to Julian day counts.
gregoriantojd() Convert Gregorian calendar dates to Julian day counts.
jddayofweek() Returns the day of the week the date is on.
jdmonthname() Returns the name of the month.
jdtofrench() Converts the Julian day count to a date in the French Republican calendar.
jdtogregorian() Converts the Julian day count to a date in the Gregorian calendar.
jdtojewish() Converts the Julian day count to a Jewish calendar date.
jdtojulian() Convert the Julian day count to the date of the Julian calendar.
jdtounix() Convert Julian day count to Unix timestamp.
jewishtojd() Converts a Jewish calendar date to a Julian day count.
juliantojd() Converts a date in the Julian calendar to a Julian day count.
unixtojd() Convert Unix timestamp to Julian day count.

PHP 5 预定义的 Calendar 常量

常量 类型 PHP 版本
CAL_GREGORIAN Integer PHP 4
CAL_JULIAN Integer PHP 4
CAL_JEWISH Integer PHP 4
CAL_FRENCH Integer PHP 4
CAL_NUM_CALS Integer PHP 4
CAL_DOW_DAYNO Integer PHP 4
CAL_DOW_SHORT Integer PHP 4
CAL_DOW_LONG Integer PHP 4
CAL_MONTH_GREGORIAN_SHORT Integer PHP 4
CAL_MONTH_GREGORIAN_LONG Integer PHP 4
CAL_MONTH_JULIAN_SHORT Integer PHP 4
CAL_MONTH_JULIAN_LONG Integer PHP 4
CAL_MONTH_JEWISH Integer PHP 4
CAL_MONTH_FRENCH Integer PHP 4
CAL_EASTER_DEFAULT Integer PHP 4.3
CAL_EASTER_ROMAN Integer PHP 4.3
CAL_EASTER_ALWAYS_GREGORIAN Integer PHP 4.3
CAL_EASTER_ALWAYS_JULIAN Integer PHP 4.3
CAL_JEWISH_ADD_ALAFIM_GERESH Integer PHP 5.0
CAL_JEWISH_ADD_ALAFIM Integer PHP 5.0
CAL_JEWISH_ADD_GERESHAYIM Integer PHP 5.0