amit
amit

Reputation: 1209

How to convert seconds to milliseconds in PHP

I want to get a difference between two dates in Php in milliseconds, How can I do this? I tried with the following code but not working for me, I am getting the result in seconds, how can I convert to milliseconds? Here is my code.

$expiration_time=$row['time'];
$date = date('Y-m-d H:i:s');
$date1 = strtotime($expiration_time);  
$date2 = strtotime($date);  
echo $diff = abs($date2 - $date1);

Upvotes: 1

Views: 5537

Answers (1)

Lulceltech
Lulceltech

Reputation: 1702

$milliseconds = strtotime($date) * 1000;

Just multiply it by 1000.

Although I do prefer to use:

$milliseconds = round(microtime(true) * 1000);

Upvotes: 3

Related Questions