setTimestamp ($unixtimestamp);
date_timestamp_set ($date_obj,$unixtimestamp);
| Parameter | DESCRIPTION |
|---|---|
| $date_obj | Required : Input date object to be assigned new value. |
| $unixtimestamp | Required: Integer , Timestamp of new date and time |
mktime() function to generate timestamp
Generate timestamp using date and time
$date = new DateTime();
$date->setTimestamp(1580774387);
echo $date->format('U = Y-m-d H:i:s'); // Output is 1580774387 = 2020-02-04 05:29:47
$date = date_create();
date_timestamp_set($date, 1671851396);
echo date_format($date, 'U = Y-m-d H:i:s') // Output is 1671851396 = 2022-12-24 08:39:56
$last_login = new DateTime(); // create a date object
$last_login->setTimestamp(1516245357); // Timestamp of 2018-01-18 08:45:57
$date = new DateTime(); // date object showing current time
$date= $date->diff($last_login);
echo $date->format('%y Years, %m Months, %d Days'); //1 Years, 0 Months, 15 Days
The above output will change as the current date is changed. Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.