PHP - Calendar unixtojd() Function
The PHP Calendar unixtojd() function is used to convert a Unix timestamp (the number of seconds since January 1, 1970) into a Julian Day Count. The Julian Day count is a running total of days since the start of the Julian Period, which can be used to calculate and compare dates.
Syntax
Below is the syntax of the PHP Calendar unixtojd() function −
int unixtojd ( ?int $timestamp = null )
Parameters
This function accepts $timestamp parameter which is a unix timestamp to convert.
Return Value
The unixtojd() function returns a julian day number as integer.
PHP Version
First introduced in core PHP 4, the unixtojd() function continues to function easily in PHP 5, PHP 7, and PHP 8.
Example 1
Here is the basic example of the PHP Calendar unixtojd() function to convert the unix timestamp into julian day count.
<?php // Convert the unix timestamp in julian day count echo(unixtojd()); ?>
Output
Here is the outcome of the following code −
2458086
Example 2
In the below PHP code we will try to use the unixtojd() function and convert a specific Unix timestamp for a known date into a Julian Day Count.
<?php // Mention specific date $timestamp = mktime(0, 0, 0, 8, 16, 2024); // August 16, 2024 // Display the result after converting the date echo unixtojd($timestamp); ?>
Output
This will generate the below output −
2460539
Example 3
This example shows converting a Unix timestamp for a future date into a Julian Day Count using the unixtojd() method.
<?php // Mention specific future date $timestamp = mktime(0, 0, 0, 1, 1, 2050); // January 1, 2050 echo unixtojd($timestamp); ?>
Output
This will create the below output −
2469808
Example 4
This example
In the following example, we are using the unixtojd() function for converting a Unix timestamp for a historical date into its related Julian Day Count.
<?php // Mention specific a historic date $timestamp = mktime(10, 2, 1869); // Gandhi Jayanti // Display the result echo unixtojd($timestamp); ?>
Output
Following is the output of the above code −
2460539