Open In App

PHP | unixtojd() Function

Last Updated : 20 Jul, 2021
Improve
Improve
Like Article
Like
Save
Share
Report

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 which 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.  

PHP




<?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);
?>


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.  

PHP




<?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);
?>


Output: 

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

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads