PHP 8.4.22 Released!

DateTime::createFromTimestamp

(PHP 8 >= 8.4.0)

DateTime::createFromTimestampCreates an instance from a Unix timestamp

Description

public static function DateTime::createFromTimestamp(int|float $timestamp): static

Creates an instance from a Unix timestamp.

Liste de paramètres

timestamp
Unix timestamp representing the date. A nombre décimal value is also accepted which allows for microsecond precision.

Valeurs de retour

Returns a new DateTime instance.

Erreurs / Exceptions

If the timestamp is outside the range [PHP_INT_MIN, PHP_INT_MAX], a DateRangeError is thrown.

Exemples

Exemple #1 DateTime::createFromTimestamp() example

<?php
$date
= DateTime::createFromTimestamp(123.456789);
echo
$date->format('Y-m-d H:i:s.u');
?>

L'exemple ci-dessus va afficher :

1970-01-01 00:02:03.456789
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top