public function TimeMachine::getCurrentTime in Preview Link 2.0.x
Same name and namespace in other branches
- 2.x tests/modules/preview_link_test_time/src/TimeMachine.php \Drupal\preview_link_test_time\TimeMachine::getCurrentTime()
Returns the current system time as an integer.
This method should be used to obtain the current system time, at the time the method was called.
This method can replace many instances of
$time = time();
with
$request_time = \Drupal::time()
->getCurrentTime();
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 is needed, use TimeInterface::getRequestTime().
Using the time service, rather than other methods, is especially important when creating tests, which require predictable timestamps.
Return value
int A Unix timestamp.
Overrides TimeInterface::getCurrentTime
See also
\Drupal\Component\Datetime\TimeInterface::getRequestTime()
\Drupal\Component\Datetime\TimeInterface::getRequestMicroTime()
\Drupal\Component\Datetime\TimeInterface::getCurrentMicroTime()
File
- tests/
modules/ preview_link_test_time/ src/ TimeMachine.php, line 49
Class
- TimeMachine
- Service used to simulate time.
Namespace
Drupal\preview_link_test_timeCode
public function getCurrentTime() {
return $this
->getTime()
->getTimestamp();
}