PHP如何使用gregoriantojd()函数进行日期转换?

函数是一个内置函数,它将格里高利历日期转换为儒略日计数。该函数接受格式为$month / $day / $year的三个参数,表示公历中的日期并将其转换为儒略日计数。

语法如下:

gregoriantojd( $month, $day, $year)

参数:该函数接受三个必选参数, 如上所示和以下内容:

  • $ month –此参数指定公历中的月份数。月数范围为1到12(含)之间。如果通过的月份数超过12或小于0, 则儒略日返回为0。
  • $ day –此参数指定公历中的日期。天数的范围是1-31(含)。如果经过的天数大于31或小于0, 则返回儒略日为0。不考虑Le年
  • $ year –此参数指定公历中的年份。
  • 返回值:该函数返回转换为儒略日计数的公历日期。

例子:

Input : $month=3, $day=31, $year=2018 
Output : 2458209

Input : $month=4, $day=27, $year=2018
Output : 2458236

下面的程序说明了gregoriantojd()函数。

程序1:下面的程序演示了gregoriantojd()函数的用法。

<?php
// PHP program to demonstrate the
// use of gregoriantojd() function 
  
// converts date to julian integer 
$jd =gregoriantojd(4, 27, 2018);
  
// prints the julian day integer
echo ( $jd );
?>

输出如下:

2458236

程序2:下面的程序演示了何时超出日期和月份。

<?php
// PHP program to demonstrate the
// use of gregoriantojd() function 
  
// converts date to julian integer 
// month is out of range
$jd =gregoriantojd(4, 32, 2018);
  
// prints the julian day integer
echo ( $jd ), "\n" ; 
  
  
// day is out of range
$jd =gregoriantojd(13, 29, 2018);
echo ( $jd ); 
?>

输出如下:

0
0

参考:http://php.net/manual/en/function.gregoriantojd.php

更多PHP开发相关内容请参考:lsbin - IT开发技术https://www.lsbin.com/

参考更多以下PHP的内容:

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值