class Time implements TimeInterface (View source)

Provides a class for obtaining system time.

Properties

protected RequestStack $requestStack

The request stack.

Methods

__construct(RequestStack $request_stack)

Constructs a Time object.

int
getRequestTime()

Returns the timestamp for the current request.

float
getRequestMicroTime()

Returns the timestamp for the current request with microsecond precision.

int
getCurrentTime()

Returns the current system time as an integer.

float
getCurrentMicroTime()

Returns the current system time with microsecond precision.

Details

__construct(RequestStack $request_stack)

Constructs a Time object.

Parameters

RequestStack $request_stack

The request stack.

int getRequestTime()

Returns the timestamp for the current request.

This method should be used to obtain the current system time at the start of the request. It will be the same value for the life of the request (even for long execution times).

If the request is not available it will fallback to the current system time.

This method can replace instances of

Return Value

int

A Unix timestamp.

float getRequestMicroTime()

Returns the timestamp for the current request with microsecond precision.

This method should be used to obtain the current system time, with microsecond precision, at the start of the request. It will be the same value for the life of the request (even for long execution times).

If the request is not available it will fallback to the current system time with microsecond precision.

This method can replace instances of

Return Value

float

A Unix timestamp with a fractional portion.

int 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

Return Value

int

A Unix timestamp.

float 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

Return Value

float

A Unix timestamp with a fractional portion.