PHP - Calendar jdmonthname() 函式



PHP Calendar 的 jdmonthname() 函式用於返回包含月份名稱的字串。mode 告訴此函式將儒略日數轉換為哪個日曆,以及要返回哪種型別的月份名稱。

語法

以下是 PHP Calendar 的 jdmonthname() 函式的語法:

string jdmonthname(int $jd, int $mode)

引數

以下是 jdmonthname() 函式的引數:

  • $jd - 它是由 Calendar_init() 返回的日曆控制代碼。

  • $mode - 它定義了將儒略日數轉換為哪個日曆,以及要返回哪種型別的月份名稱。

模式值如下:

  • 0 - 格里高利 - 簡寫(Jan、Feb、Mar 等)
  • 1 - 格里高利(January、February、March 等)
  • 2 - 儒略 - 簡寫(Jan、Feb、Mar 等)
  • 3 - 儒略(January、February、March 等)
  • 4 - 猶太(Tishri、Heshvan、Kislev 等)
  • 5 - 法國共和(Vendemiaire、Brumaire、Frimaire 等)

返回值

jdmonthname() 函式返回給定儒略日和日曆的月份名稱。

PHP 版本

jdmonthname() 函式首次引入到 PHP 4 的核心版本中,並在 PHP 5、PHP 7 和 PHP 8 中繼續輕鬆執行。

示例 1

首先,我們將向您展示 PHP Calendar jdmonthname() 函式的基本示例,以在儒略日數的幫助下獲取月份的全稱。

<?php
   // January 1, 2000 in the Julian calendar
   $jd = 2451545; 
   
   // Get the full month name
   $monthName = jdmonthname($jd, 0); 
   
   // Display the result
   echo "The full month name is: $monthName"; 
?>

輸出

以下是以下程式碼的結果:

The full month name is: January

示例 2

此示例演示瞭如何使用儒略日數在 jdmonthname() 函式的幫助下查詢月份的縮寫名稱。

<?php
   // January 1, 2000 in the Julian calendar
   $jd = 2451545; 

   // Get the abbreviated month name
   $monthName = jdmonthname($jd, 1); 

   // Display the result
   echo "The abbreviated month name is: $monthName"; 
?> 

輸出

這將生成以下輸出:

The abbreviated month name is: Jan

示例 3

此示例演示瞭如何使用儒略日數在 jdmonthname() 函式的幫助下獲取月份的數字表示形式。

<?php
   // December 1, 2000 in the Julian calendar
   $jd = 2451535; 
   
   // Get the numeric month representation
   $monthNumber = jdmonthname($jd, 2); 

   // Display the result
   echo "The numeric month is: $monthNumber"; 
?> 

輸出

這將建立以下輸出:

The numeric month is: 12
php_function_reference.htm
廣告

© . All rights reserved.