dayofweek php,PHP jddayofweek()用法及代码示例

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值