jddayofweek()函数是PHP中的内置函数,它返回在参数中传递的儒略整数的给定星期几。返回值根据函数中传递的模式分为三种类型。它返回代表星期几的三种类型的值。如果将模式作为0传递,则返回0、1、2…,表示星期天,星期一,星期二…当将1作为模式传递时,返回星期日,星期一,星期二…。传递2作为模式时,它返回缩写Sun,Mon,Tue…作为星期几。
用法:
jddayofweek($jd, $mode)
参数:该函数接受两个参数,如上所示和以下所述。
$jd-这是一个必填参数,用于将儒略日指定为整数。使用gregoriantojd($month,$day,$year)将公历日期转换为儒略日整数。
$mode-这是一个可选参数,用于指定返回值的类型。它接受0-2(含)范围内的值。默认值为0。以下描述三种返回模式:0-当mode传递为0时,它返回0、1、2、3。分别表示星期日,星期一,星期二…为星期几。当不丢失任何模式参数或传递任何超出范围的值时,这是模式的默认值。
1个-当模式设为1时,它将返回星期日,星期一,星期二…
2-当mode作为2传递时,它返回MSunday,Monday,Tuesdae的缩写形式为Sun,Mon,Tues.。
返回值:如上所述,函数根据在参数中传递的模式值返回星期几。
例子:
Input : $jd = 4/27/2018 , mode=0
Output : 5
Input : $jd = 4/27/2018 , mode=1
Output : Friday
以下示例程序旨在说明jddayofweek()函数
程序1:下面的程序演示了不通过模式和采用默认模式时的输出。
// PHP program to demonstrate the
// use of jddayofweek() function
// when second parameter is not passed
// converts date to julian integer
$jd=gregoriantojd(4, 27, 2018);
// prints the day on the given date
echo jddayofweek($jd);
?>
输出:
5
程序2:下面的程序演示了模式为1时的输出。
// PHP program to demonstrate the
// use of jddayofweek() function
// when mode is 1
// converts date to julian integer
$jd=gregoriantojd(4, 27, 2018);
// prints the day on the given date
echo jddayofweek($jd, 1);
?>
输出:
Friday
程序3:下面的程序演示了mode为2时的输出。
// PHP program to demonstrate the
// use of jddayofweek() function
// when mode is 2
// converts date to julian integer
$jd=gregoriantojd(4, 27, 2018);
// prints the day on the given date
echo jddayofweek($jd, 2);
?>
输出:
Fri
程序4:下面的程序演示了模式超出范围时的输出。
// PHP program to demonstrate the
// use of jddayofweek() function
// when mode is out of range
// converts date to julian integer
$jd=gregoriantojd(4, 27, 2018);
// prints the day on the given date
echo jddayofweek($jd, 4);
?>
输出:
5