YouTip LogoYouTip

Func Date Microtime

```html PHP microtime() Function

PHP microtime() Function

-- Learn not just technology, but also dreams!

PHP Tutorial

PHP Forms

PHP Advanced Tutorial

PHP 7 New Features

PHP Database

PHP microtime() Function

The microtime() function returns the current Unix timestamp with microseconds.

If the optional parameter get_as_float is set to TRUE, it returns a floating point number representing the Unix timestamp (in seconds).

Syntax

microtime(get_as_float)

Parameters

ParameterDescription
get_as_floatOptional. If TRUE, the function returns a floating point number. If FALSE, it returns a string in the format "msec sec".

Return Value

If get_as_float is TRUE, returns a float. Otherwise, returns a string like "0.123456 1234567890".

Example 1

<?php
echo microtime();
?>

Output:

0.12345600 1234567890

Example 2

<?php
echo microtime(true);
?>

Output:

1234567890.1234

Example 3

<?php
// Calculate script execution time
$start = microtime(true);

// Some code to execute
for ($i = 0; $i < 100000; $i++) {
    // Do nothing
}

$end = microtime(true);
echo "Execution time: " . ($end - $start) . " seconds";
?>

Output:

Execution time: 0.0032 seconds
```
← Func Date MktimeFunc Date Localtime β†’