Open In App

How to Get Current Time in Milliseconds in PHP ?

Last Updated : 05 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

In this article, we will see how to get the current time in milliseconds in PHP. There are mainly three methods to get the current time in milliseconds and they are the following:

Approach 1: Using microtime() Function

The microtime() function in PHP gets the current time in seconds. We can simply multiply the resultant value by 1000 to convert the current time from seconds to milliseconds.

 

Example:

PHP




<?php
  
$current_time = round(microtime(true) * 1000);
echo $current_time;
  
?>


Output

1704135351653

Approach 2: Using DateTime Class with format() Function

The DateTime class in conjunction with the format() function directly returns the current time in milliseconds with the Uv parameter.

Example:

PHP




<?php
      
$current_time = (new DateTime())->format('Uv');
echo $current_time;
  
?>


Output

1704135453553

Approach 3: Using date_create() with format() Function

The date_create() class, which returns a new DateTime class object, in conjunction with the format method returns the current time in milliseconds with the Uv parameter.

Example:

PHP




<?php
  
$current_time = date_create()->format('Uv');
echo $current_time;
  
?>


Output

1704135512433


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads