In this article, you will learn how to set the date and time in PHP according to the UNIX timestamp. The date_timestamp_set() function accepts the UNIX timestamp and sets the corresponding Date and Time in the result.
What is the syntax of the date_timestamp_set() function in PHP?
date_timestamp_set(object, unixtimestamp)
Parameter | Description |
---|---|
object | Required. Specifies a DateTime object returned by date_create(). This function modifies this object |
unixtimestamp | Required. Specifies a Unix timestamp representing the date |
Examples of the date_timestamp_set() function
Example 1.
<?php
$d=date_create();
date_timestamp_set($d,1261702212);
echo date_format($d,"U = Y-m-d H:i:s");
?>