php new date from timestamp code example
Example 1: php timestamp to date
<?php
echo date('m/d/Y H:i:s', 1541843467);
?>
Example 2: php date timestamp now
$date = date('Y-m-d H:i:s');
$date = date('Y/m/d H:i:s');
$date = '2012-03-06 17:33:07';
$date = '2012/03/06 17:33:07';
date_default_timezone_set('Africa/Nairobi');
$date = date('Y-m-d H:i:s');
$date = date('Y/m/d H:i:s');
Example 3: php date object to timestamp
$date = new DateTime();
echo $date->getTimestamp();
Example 4: php timestamp
<?php
$nextWeek = time() + (7 * 24 * 60 * 60);
echo 'Now: '. date('Y-m-d') ."\n";
echo 'Next Week: '. date('Y-m-d', $nextWeek) ."\n";
echo 'Next Week: '. date('Y-m-d', strtotime('+1 week')) ."\n";
?>
Example 5: php datetime from timestamp
$ts = 1171502725;
$date = new DateTime("@$ts");