function Time::getCurrentMicroTime
Same name and namespace in other branches
- 8.9.x core/lib/Drupal/Component/Datetime/Time.php \Drupal\Component\Datetime\Time::getCurrentMicroTime()
- 10 core/lib/Drupal/Component/Datetime/Time.php \Drupal\Component\Datetime\Time::getCurrentMicroTime()
- 11.x core/lib/Drupal/Component/Datetime/Time.php \Drupal\Component\Datetime\Time::getCurrentMicroTime()
Returns the current system time with microsecond precision.
This method should be used to obtain the current system time, with microsecond precision, at the time the method was called.
This method can replace many instances of
$microtime = microtime();
$microtime = microtime(TRUE);
with
$request_time = \Drupal::time()->getCurrentMicroTime();
or the equivalent using the injected service.
This method should only be used when the current system time is actually needed, such as with timers or time interval calculations. If only the time at the start of the request and microsecond precision is needed, use TimeInterface::getRequestMicroTime().
Using the time service, rather than other methods, is especially important when creating tests, which require predictable timestamps.
Return value
float A Unix timestamp with a fractional portion.
Overrides TimeInterface::getCurrentMicroTime
1 call to Time::getCurrentMicroTime()
- Time::getRequestMicroTime in core/
lib/ Drupal/ Component/ Datetime/ Time.php - Returns the timestamp for the current request with microsecond precision.
File
-
core/
lib/ Drupal/ Component/ Datetime/ Time.php, line 65
Class
- Time
- Provides a class for obtaining system time.
Namespace
Drupal\Component\DatetimeCode
public function getCurrentMicroTime() {
return microtime(TRUE);
}
Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.