php datetime to milliseconds code example

Example 1: php datetime object get unix timestamp

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

Example 2: php milliseconds

//Timing executation time of script
$startTime = microtime(true); //get time in micro seconds(1 millionth)
usleep(250); 
$endTime = microtime(true);

echo "milliseconds to execute:". ($endTime-$startTime)*1000;

Example 3: show date time with milliseconds php

$now = DateTime::createFromFormat('U.u', microtime(true));
echo $now->format("m-d-Y H:i:s.u");

Tags:

Php Example