date_timestamp_set

Sets the date and time based on an Unix timestamp

Syntax

date_timestamp_set ( DateTime $object , int $timestamp ) : DateTime

Parameters

object

A DateTime object returned by date_create(). The function modifies this object.

timestamp

Unix timestamp representing the date.

Return

Returns the DateTime object for method chaining or FALSE on failure.

Examples

object timestamp

<?

$object = date_create();
$timestamp = date_timestamp_get($object);

date_timestamp_set($object, $timestamp);

echo date_format($object, "U = Y-m-d H:i:s");

?>
1638814739 = 2021-12-06 18:18:59

Return

<?

$object = date_create();
$timestamp = date_timestamp_get($object);

$return = date_timestamp_set($object, $timestamp);

echo date_format($return, "U = Y-m-d H:i:s");

?>
1638814739 = 2021-12-06 18:18:59

PHP

Home Menu