class Time extends DateTime implements TimeInterface

Extension of the PHP DateTime class.

Traits

Time trait.

Methods

__construct(string $time = 'now', string|DateTimeZone|null $timeZone = null)

Constructor.

from TimeTrait
static TimeTrait
now(string|DateTimeZone|null $timeZone = null)

Returns a new instance set to the current time.

from TimeTrait
static TimeTrait|false
createFromDate(int $year, int|null $month = null, int|null $day = null, string|DateTimeZone|null $timeZone = null)

Returns a new instance according to the specified date.

from TimeTrait
static TimeTrait|false
createFromTimestamp(int $timestamp, string|DateTimeZone|null $timeZone = null)

Returns a new instance according to the specified UNIX timestamp.

from TimeTrait
static TimeTrait|false
createFromDOSTimestamp(int $timestamp, string|DateTimeZone|null $timeZone = null)

Returns a new instance according to the specified DOS timestamp.

from TimeTrait
static TimeTrait|false
createFromFormat(string $format, string $time, string|DateTimeZone|null $timeZone = null)

Returns a new instance according to the specified time string.

from TimeTrait
$this|TimeTrait|false
setTimezone(string|DateTimeZone $timeZone)

Sets the time zone.

from TimeTrait
$this|TimeTrait|false
forward(int $seconds)

Move forward in time by x seconds.

from TimeTrait
$this|TimeTrait|false
rewind(int $seconds)

Move backward in time by x seconds.

from TimeTrait
int
getDOSTimestamp()

Returns the DOS timestamp.

from TimeTrait
bool
isLeapYear()

Returns TRUE if the year is a leap year and FALSE if not.

from TimeTrait
array
daysInMonths()

Returns an array containing the number of days in each month of the year.

from TimeTrait
int
daysInMonth()

Returns the number of days in the current or specified month.

from TimeTrait
string
formatLocalized(string $format)

Returns a formatted date string according to current locale settings.

from TimeTrait
$this
copy()

Returns a copy of the current instance.

getImmutable()

Returns an immutable instance of the current instance.

Details

in TimeTrait at line 30
__construct(string $time = 'now', string|DateTimeZone|null $timeZone = null)

Constructor.

Parameters

string $time A date/time string
string|DateTimeZone|null $timeZone A valid time zone or a DateTimeZone object

in TimeTrait at line 46
static TimeTrait now(string|DateTimeZone|null $timeZone = null)

Returns a new instance set to the current time.

Parameters

string|DateTimeZone|null $timeZone A valid time zone or a DateTimeZone object

Return Value

TimeTrait

in TimeTrait at line 60
static TimeTrait|false createFromDate(int $year, int|null $month = null, int|null $day = null, string|DateTimeZone|null $timeZone = null)

Returns a new instance according to the specified date.

Parameters

int $year Year
int|null $month Month (1 to 12)
int|null $day Day of month (1 to 31)
string|DateTimeZone|null $timeZone A valid time zone or a DateTimeZone object

Return Value

TimeTrait|false

in TimeTrait at line 78
static TimeTrait|false createFromTimestamp(int $timestamp, string|DateTimeZone|null $timeZone = null)

Returns a new instance according to the specified UNIX timestamp.

Parameters

int $timestamp UNIX timestamp
string|DateTimeZone|null $timeZone A valid time zone or a DateTimeZone object

Return Value

TimeTrait|false

in TimeTrait at line 90
static TimeTrait|false createFromDOSTimestamp(int $timestamp, string|DateTimeZone|null $timeZone = null)

Returns a new instance according to the specified DOS timestamp.

Parameters

int $timestamp DOS timestamp
string|DateTimeZone|null $timeZone A valid time zone or a DateTimeZone object

Return Value

TimeTrait|false

in TimeTrait at line 112
static TimeTrait|false createFromFormat(string $format, string $time, string|DateTimeZone|null $timeZone = null)

Returns a new instance according to the specified time string.

Parameters

string $format The format that the passed in string should be in
string $time String representing the time
string|DateTimeZone|null $timeZone A valid time zone or a DateTimeZone object

Return Value

TimeTrait|false

in TimeTrait at line 137
$this|TimeTrait|false setTimezone(string|DateTimeZone $timeZone)

Sets the time zone.

Parameters

string|DateTimeZone $timeZone A valid time zone or a DateTimeZone object

Return Value

$this|TimeTrait|false

in TimeTrait at line 153
$this|TimeTrait|false forward(int $seconds)

Move forward in time by x seconds.

Parameters

int $seconds Number of seconds

Return Value

$this|TimeTrait|false

in TimeTrait at line 164
$this|TimeTrait|false rewind(int $seconds)

Move backward in time by x seconds.

Parameters

int $seconds Number of seconds

Return Value

$this|TimeTrait|false

in TimeTrait at line 174
int getDOSTimestamp()

Returns the DOS timestamp.

Return Value

int

in TimeTrait at line 196
bool isLeapYear()

Returns TRUE if the year is a leap year and FALSE if not.

Return Value

bool

in TimeTrait at line 213
array daysInMonths()

Returns an array containing the number of days in each month of the year.

Return Value

array

in TimeTrait at line 237
int daysInMonth()

Returns the number of days in the current or specified month.

Return Value

int

in TimeTrait at line 248
string formatLocalized(string $format)

Returns a formatted date string according to current locale settings.

Parameters

string $format Date format

Return Value

string

at line 29
$this copy()

Returns a copy of the current instance.

Return Value

$this

at line 39
TimeImmutable getImmutable()

Returns an immutable instance of the current instance.

Return Value

TimeImmutable