jdmonthname() 函数用于返回指定儒略日数对应的月份名称。
这个函数可以根据不同的日历系统返回相应的月份名称,在日历应用、历史日期显示和多语言支持中非常有用。
jdmonthname(int $julian_day, int $mode): string
| 参数 | 描述 |
|---|---|
| julian_day | 必需。指定儒略日数 |
| mode | 必需。指定日历系统和名称格式 |
返回一个字符串,表示指定儒略日数在相应日历系统中的月份名称。
| 常量 | 值 | 描述 |
|---|---|---|
| CAL_MONTH_GREGORIAN_SHORT | 0 | 公历月份缩写(Jan, Feb, ...) |
| CAL_MONTH_GREGORIAN_LONG | 1 | 公历月份全称(January, February, ...) |
| CAL_MONTH_JULIAN_SHORT | 2 | 儒略历月份缩写 |
| CAL_MONTH_JULIAN_LONG | 3 | 儒略历月份全称 |
| CAL_MONTH_JEWISH | 4 | 犹太历月份名称 |
| CAL_MONTH_FRENCH | 5 | 法国共和历月份名称 |
| 月份 | 英文全称 | 英文缩写 | 中文 |
|---|---|---|---|
| 1 | January | Jan | 一月 |
| 2 | February | Feb | 二月 |
| 3 | March | Mar | 三月 |
| 4 | April | Apr | 四月 |
| 5 | May | May | 五月 |
| 6 | June | Jun | 六月 |
| 7 | July | Jul | 七月 |
| 8 | August | Aug | 八月 |
| 9 | September | Sep | 九月 |
| 10 | October | Oct | 十月 |
| 11 | November | Nov | 十一月 |
| 12 | December | Dec | 十二月 |
| 月份编号 | 法语名称 | 中文含义 |
|---|---|---|
| 1 | Vendémiaire | 葡月 |
| 2 | Brumaire | 雾月 |
| 3 | Frimaire | 霜月 |
| 4 | Nivôse | 雪月 |
| 5 | Pluviôse | 雨月 |
| 6 | Ventôse | 风月 |
| 7 | Germinal | 芽月 |
| 8 | Floréal | 花月 |
| 9 | Prairial | 牧月 |
| 10 | Messidor | 获月 |
| 11 | Thermidor | 热月 |
| 12 | Fructidor | 果月 |
// 获取2000年1月1日的月份名称
$jd = gregoriantojd(1, 1, 2000);
$month_short = jdmonthname($jd, CAL_MONTH_GREGORIAN_SHORT);
$month_long = jdmonthname($jd, CAL_MONTH_GREGORIAN_LONG);
echo "2000年1月1日的月份:\n";
echo "缩写: {$month_short}\n";
echo "全称: {$month_long}";
输出结果:
2000年1月1日的月份:
缩写: Jan
全称: January
// 比较不同日历系统的月份名称
$jd = gregoriantojd(1, 1, 2000);
echo "2000年1月1日在不同日历系统中的月份名称:\n";
echo "公历缩写: " . jdmonthname($jd, CAL_MONTH_GREGORIAN_SHORT) . "\n";
echo "公历全称: " . jdmonthname($jd, CAL_MONTH_GREGORIAN_LONG) . "\n";
echo "儒略历缩写: " . jdmonthname($jd, CAL_MONTH_JULIAN_SHORT) . "\n";
echo "儒略历全称: " . jdmonthname($jd, CAL_MONTH_JULIAN_LONG) . "\n";
echo "犹太历: " . jdmonthname($jd, CAL_MONTH_JEWISH) . "\n";
echo "法国共和历: " . jdmonthname($jd, CAL_MONTH_FRENCH);
输出结果:
2000年1月1日在不同日历系统中的月份名称:
公历缩写: Jan
公历全称: January
儒略历缩写: Dec
儒略历全称: December
犹太历: Tevet
法国共和历: Nivose
// 获取重要历史事件发生的月份名称
$historical_dates = [
"美国独立宣言" => [7, 4, 1776],
"人类首次登月" => [7, 20, 1969],
"柏林墙倒塌" => [11, 9, 1989],
"互联网诞生" => [1, 1, 1983]
];
foreach ($historical_dates as $event => $date) {
list($month, $day, $year) = $date;
$jd = gregoriantojd($month, $day, $year);
$month_name = jdmonthname($jd, CAL_MONTH_GREGORIAN_LONG);
echo "{$event}: {$month_name} {$day}, {$year}\n";
}
输出结果:
美国独立宣言: July 4, 1776
人类首次登月: July 20, 1969
柏林墙倒塌: November 9, 1989
互联网诞生: January 1, 1983
// 法国共和历月份名称示例
echo "法国共和历月份名称示例:\n";
for ($month = 1; $month <= 12; $month++) {
// 使用共和历元年葡月1日作为基准
$jd = frenchtojd($month, 1, 1);
$month_name = jdmonthname($jd, CAL_MONTH_FRENCH);
echo "月份 {$month}: {$month_name}\n";
}
输出结果:
法国共和历月份名称示例:
月份 1: Vendemiaire
月份 2: Brumaire
月份 3: Frimaire
月份 4: Nivose
月份 5: Pluviose
月份 6: Ventose
月份 7: Germinal
月份 8: Floreal
月份 9: Prairial
月份 10: Messidor
月份 11: Thermidor
月份 12: Fructidor
// 创建多语言月份显示函数
function get_month_info($month, $day, $year, $calendar = CAL_GREGORIAN) {
if ($calendar == CAL_GREGORIAN) {
$jd = gregoriantojd($month, $day, $year);
} elseif ($calendar == CAL_FRENCH) {
$jd = frenchtojd($month, $day, $year);
} else {
$jd = gregoriantojd($month, $day, $year);
}
return [
'gregorian_short' => jdmonthname($jd, CAL_MONTH_GREGORIAN_SHORT),
'gregorian_long' => jdmonthname($jd, CAL_MONTH_GREGORIAN_LONG),
'julian_short' => jdmonthname($jd, CAL_MONTH_JULIAN_SHORT),
'julian_long' => jdmonthname($jd, CAL_MONTH_JULIAN_LONG),
'jewish' => jdmonthname($jd, CAL_MONTH_JEWISH),
'french' => jdmonthname($jd, CAL_MONTH_FRENCH)
];
}
// 使用函数获取月份信息
$info = get_month_info(1, 1, 2000);
echo "2000年1月1日的月份信息:\n";
foreach ($info as $key => $value) {
echo ucfirst(str_replace('_', ' ', $key)) . ": {$value}\n";
}
输出结果:
2000年1月1日的月份信息:
Gregorian short: Jan
Gregorian long: January
Julian short: Dec
Julian long: December
Jewish: Tevet
French: Nivose
// 生成一年的月份名称列表
$year = 2024;
echo "{$year}年各月份名称:\n";
for ($month = 1; $month <= 12; $month++) {
$jd = gregoriantojd($month, 15, $year); // 使用月中日期
$month_short = jdmonthname($jd, CAL_MONTH_GREGORIAN_SHORT);
$month_long = jdmonthname($jd, CAL_MONTH_GREGORIAN_LONG);
echo "{$month}月: {$month_short} ({$month_long})\n";
}
输出结果:
2024年各月份名称:
1月: Jan (January)
2月: Feb (February)
3月: Mar (March)
4月: Apr (April)
5月: May (May)
6月: Jun (June)
7月: Jul (July)
8月: Aug (August)
9月: Sep (September)
10月: Oct (October)
11月: Nov (November)
12月: Dec (December)
| 返回值: | 返回月份名称字符串 |
|---|---|
| PHP 版本: | 4.0+ |
| 依赖扩展: | 需要启用Calendar扩展 |
| 名称语言: | 返回的月份名称是英文或相应语言的名称 |
jdmonthname() 函数在以下场景中特别有用:
jddayofweek() - 返回儒略日数的星期几gregoriantojd() - 将公历日期转换为儒略日数jdtogregorian() - 将儒略日数转换为公历日期frenchtojd() - 将法国共和历日期转换为儒略日数jdtofrench() - 将儒略日数转换为法国共和历日期cal_info() - 获取日历系统信息