PHP | unixtojd() Function

The unixtojd() is a built-in function in PHP which converts the unix timestamp to Julian Day count. The UNIX timestamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on January 1st, 1970 at UTC. Therefore, the UNIX timestamp is merely the number of seconds between a particular date and the Unix Epoch.

Syntax:

unixtojd( $unix )

Parameter: The function accepts a single parameter as shown above which is optional. $unix specifies the unix timestamp whihc is converted to Julian Day count.



Return Value: The function returns the unix timestamp passed as parameter converted to Julian day Integer. If no parameter is passed, it returns the current Julian Day integer. We can convert the Julian day integer to Gregorian date to know the exact date using jdtogregorian() function.

Examples:

Input : $unix = 1524909427
Output : 2458237
Explanation: The Gregorian date is 4/28/2018 of 
the given unix timestamp 

Input : $unix = 5677896
Output : 2440653
Explanation: The Gregorian date is 3/7/1970 of 
the given unix timestamp 

Note: The function can only take Julian Day integer till Gregorian date 1/19/2038 since on this date the Unix Time Stamp will cease to work due to a 32-bit overflow.

Below programs illustrate the unixtojd() Function.

Program 1: The program below demonstrates the use of function when no parameter is passed.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to demonstrate the use of unixtojd() 
// function when no parameter is passed 
  
// takes the current date as unix timestamp 
$jd = unixtojd();
  
// prints the julian Day integer
echo "The Julian Day integer is ", ($jd), "\n"
  
// prints the corresponding Gregorian date 
echo "The Gregorian date is ", jdtogregorian($jd);
?>

chevron_right


Output:

The Julian Day integer is 2458237
The Gregorian date is 4/28/2018

Program 2: The program below demonstrates the use of function when parameter is passed.

filter_none

edit
close

play_arrow

link
brightness_4
code

<?php
// PHP program to demonstrate the use of unixtojd() 
// function when parameter is passed 
  
// takes a unix timestamp in parameter
$jd = unixtojd(5677896);
  
// prints the julian Day integer
echo "The Julian Day integer is ", ($jd), "\n"
  
// prints the corresponding Gregorian date 
echo "The Gregorian date is ", jdtogregorian($jd);
?>

chevron_right


Output:

The Julian Day integer is 2440653
The Gregorian date is 3/7/1970

Reference: http://php.net/manual/en/function.unixtojd.php



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.