Home >>PHP Date Time Functions >PHP date_timestamp_set() Function
PHP date_timestamp_set() function is used to sets the date and time based on the given Unix timestamp. It returns the DateTime object for method chaining on success or False on failure. It accepts two different parameters $object and $unixtimestamp.
Syntax:
date_timestamp_set(object, unixtimestamp);
Parameter | Description |
---|---|
object | This is a required parameter. This parameter defines the DateTime object returned by date_create(). |
unixtimestamp | This is a required parameter. This parameter defines the Unix timestamp representing the date. |
Here is an example of date_timestamp_set() function in PHP:
<html> <body> <?php $date=date_create(); date_timestamp_set($date,1580534023); echo date_format($date,"Y-m-d H:i:s"); ?> </body> </html>
Example 2:
<html> <body> <?php $date=date_create("31-01-2000"); date_timestamp_set($date,1581638400); echo date_format($date,"d-M-Y H:i:s"); ?> </body> </html>