Converts a Julian day number into a date in the requested calendar.
What Is cal_from_jd() in PHP?
Converts a Julian day number into a date in the requested calendar.
Its syntax is:
cal_from_jd(int $julian_day, int $calendar): array
Parameters:
$julian_day— Accepted as int; required argument.$calendar— Accepted as int; required argument.
Return type: array. A Julian day number is a day count, not a UNIX timestamp. Calendar selection changes the fields.
Availability: Requires the calendar extension.
Example 1: Basic Usage
<?php
print_r(cal_from_jd(2460000, CAL_GREGORIAN));
Output:
Array
(
[date] => 2/24/2023
[month] => 2
[day] => 24
[year] => 2023
[dow] => 5
[abbrevdayname] => Fri
[dayname] => Friday
[abbrevmonth] => Feb
[monthname] => February
)
A Julian day number is a day count, not a UNIX timestamp. Calendar selection changes the fields.
Example 2: A Different Input
<?php
echo cal_from_jd(2460000, CAL_JEWISH)["date"];
Output:
7/3/5783
A Julian day number is a day count, not a UNIX timestamp. Calendar selection changes the fields.
Practical Example: Applying It in a Program
<?php
$julianDays = [2460000,2460001]; foreach ($julianDays as $julianDay) { $dateParts = cal_from_jd($julianDay, CAL_GREGORIAN); echo $dateParts["date"] . PHP_EOL; }
Output:
2/24/2023
2/25/2023
A Julian day number is a day count, not a UNIX timestamp. Calendar selection changes the fields.
Important Behavior and Edge Cases
- Key behavior: A Julian day number is a day count, not a UNIX timestamp. Calendar selection changes the fields.
- Environment: Requires the calendar extension.
Comparison With Related Functions
| Function | Purpose |
|---|---|
cal_from_jd() | Converts a Julian day number into a date in the requested calendar. |
cal_to_jd() | cal_to_jd() converts calendar parts to a Julian day number; cal_from_jd() converts that number back to a date. |
Common Beginner Mistakes
| Mistake | Correct Approach |
|---|---|
| Ignoring this behavior: A Julian day number is a day count, not a UNIX timestamp | A Julian day number is a day count, not a UNIX timestamp. Calendar selection changes the fields. |
Key Takeaways
- Converts a Julian day number into a date in the requested calendar.
- A Julian day number is a day count, not a UNIX timestamp. Calendar selection changes the fields.
- Requires the calendar extension.
Summary: A Julian day number is a day count, not a UNIX timestamp. Calendar selection changes the fields.