get timestamp php code example

Example 1: php get current date and time

$today = date("F j, Y, g:i a");   // October 30, 2019, 10:42 pm
$today = date("D M j G:i:s T Y"); // Wed Oct 30 22:42:18 UTC 2019
$today = date("Y-m-d H:i:s");     // 2019-10-30 22:42:18(MySQL DATETIME format)

Example 2: php timestamp to date

<?php 
echo date('m/d/Y H:i:s', 1541843467); 
?>

Example 3: php datetime object get unix timestamp

$date = new DateTime();
echo $date->getTimestamp();

Example 4: timestamp php

<?php
$date = new DateTime();
echo $date->getTimestamp();
?>

Example 5: unix timestamp in php

strtotime("now");

// strtotime is a function that will take a string parameter 
// that specifies a date, and returns a unix time stamp bassed
// on that

echo strtotime("2020-02-24");

// prints: 1582502400

Example 6: php timestamp

<?php

echo time();

?>

Tags:

Php Example