PHP Function Reference

PHP jdtounix() Function



The PHP jdtounix() function returns a Unix timestamp corresponding to the Julian Day given in julian_day. The time returned is UTC.

Note: Unix timestamp indicates the number of seconds since midnight of January 1, 1970 (Gregorian Calendar).

Syntax

jdtounix(julian_day)

Parameters

julian_day Required. Specify a Julian day number between 2440588 and 106751993607888 on 64bit systems, or between 2440588 and 2465443 on 32bit systems.

Return Value

Returns unix timestamp for the start (midnight, not noon) of the given Julian day.

Exceptions

If julian_day is outside of the allowed range, a ValueError is thrown.

Example:

The example below shows the usage of jdtounix() function.

<?php
//converting a Gregorian date
//to Julian integer 
$jd = gregoriantojd(10, 2, 2015);
  
//displaying the Julian day integer 
echo "The Julian day integer is: $jd \n";
  
//converting the Julian day integer 
//to Unix timestamp
$date = jdtounix($jd);
  
//displaying the Unix timestamp
echo "The Unix timestamp is: $date \n"; 
?>

The output of the above code will be:

The Julian day integer is: 2457298 
The Unix timestamp is: 1443744000 

Example: Overflow behavior

Consider one more example to see the overflow behavior of this function.

<?php
//converting a Gregorian date
//to Julian integer 
$jd = gregoriantojd(10, 2, 1950);
  
//displaying the Julian day integer 
echo "The Julian day integer is: $jd \n";
  
//converting the Julian day integer 
//to Unix timestamp
//ValueError is thrown as the $jd
//is outside of the allowed range
$date = jdtounix($jd);
  
//displaying the Unix timestamp
echo "The Unix timestamp is: $date \n"; 
?>

The output of the above code will be:

The Julian day integer is: 2433557 

PHP Fatal error:  Uncaught ValueError: jday must be between 2440588 and 106751993607888 in Main.php:13
Stack trace:
#0 Main.php(13): jdtounix()
#1 {main}
  thrown in Main.php on line 13

❮ PHP Calendar Reference