Menu Home

date_timestamp_set

osbo.com | PHP | Functions | 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");

?>
1624250780 = 2021-06-21 04:46:20

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

?>
1624250780 = 2021-06-21 04:46:20

PHP