CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • AttributeResolver
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
      • Exception
      • Formatter
      • Middleware
      • Parser
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class Time

Extends time class provided by Chronos.

Adds handy methods and locale-aware formatting helpers.

Namespace: Cake\I18n

Constants

  • string
    DEFAULT_TO_STRING_FORMAT ¶
    'H:i:s'

    Default format to use for __toString method.

  • int
    TICKS_PER_DAY ¶
    self::TICKS_PER_HOUR * 24
  • int
    TICKS_PER_HOUR ¶
    self::TICKS_PER_MINUTE * 60
  • int
    TICKS_PER_MICROSECOND ¶
    1
  • int
    TICKS_PER_MINUTE ¶
    self::TICKS_PER_SECOND * 60
  • int
    TICKS_PER_SECOND ¶
    1000000

Property Summary

  • $formatters protected static
    array<string, \IntlDateFormatter>

    In-memory cache of date formatters

  • $jsonEncodeFormat protected static
    Closure|string|int

    The format to use when converting this object to JSON.

    The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details)

  • $niceFormat public static
    string|int

    The format to use when formatting a time using Cake\I18n\Time::nice()

    The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details)

  • $ticks protected
    int
  • $toStringFormat protected static
    array|string|int

    The format to use when formatting a time using Cake\I18n\Time::i18nFormat() and __toString.

    The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details)

Method Summary

  • __construct() public

    Copies time from onther instance or from time string in the format HH[:.]mm or HH[:.]mm[:.]ss.u.

    Defaults to server time.

  • __toString() public

    Format the instance as a string using the set format

  • addHours() public

    Returns a new instance with the given number of hours added.

    Arithmetic wraps around midnight: adding 2 hours to 23:00:00 yields 01:00:00; subtracting 2 hours from 00:00:00 yields 22:00:00.

  • addMinutes() public

    Returns a new instance with the given number of minutes added.

    Wraps around midnight like {@see self::addHours()}.

  • addSeconds() public

    Returns a new instance with the given number of seconds added.

    Wraps around midnight like {@see self::addHours()}.

  • addTicks() protected

    Adds a tick (microsecond) delta and wraps into [0, TICKS_PER_DAY).

  • between() public

    Returns whether time is between time range.

  • closest() public

    Returns the ChronosTime closest to this instance.

  • diff() public

    Returns the difference between this time and a target time as a DateInterval.

    Matches the signature of DateTimeInterface::diff() — defaults to a signed interval. Pass $absolute = true to drop the sign.

  • diffInHours() public

    Returns the difference in whole hours between this time and another.

  • diffInMinutes() public

    Returns the difference in whole minutes between this time and another.

  • diffInSeconds() public

    Returns the difference in whole seconds between this time and another.

  • diffInTicks() protected
  • endOfDay() public static

    Returns instance set to end of day - either 23:59:59 or 23:59:59.999999 if $microseconds is true

  • endOfHour() public

    Sets time to the end of the current hour.

  • equals() public

    Returns whether time is equal to target time.

  • farthest() public

    Returns the ChronosTime farthest from this instance.

  • format() public

    Formats string using the same syntax as DateTimeImmutable::format().

    As this uses DateTimeImmutable::format() to format the string, non-time formatters will still be interpreted. Be sure to escape those characters first.

  • formatObject() protected

    Returns a translated and localized date string. Implements what IntlDateFormatter::formatObject() is in PHP 5.5+

  • getHours() public

    Returns clock hours.

  • getMicroseconds() public

    Returns clock microseconds.

  • getMinutes() public

    Returns clock minutes.

  • getSeconds() public

    Return clock seconds.

  • greaterThan() public

    Returns whether time is greater than target time.

  • greaterThanOrEquals() public

    Returns whether time is greater than or equal to target time.

  • i18nFormat() public

    Returns a formatted string for this time object using the preferred format and language for the specified locale.

    It is possible to specify the desired format for the string to be displayed. You can either pass IntlDateFormatter constants as the first argument of this function, or pass a full ICU date formatting string as specified in the following resource: https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax.

    Examples

    $time = new Time('23:10:10');
    $time->i18nFormat();
    $time->i18nFormat(\IntlDateFormatter::FULL);
    $time->i18nFormat("HH':'mm':'ss");

    You can control the default format used through Time::setToStringFormat().

    You can read about the available IntlDateFormatter constants at https://secure.php.net/manual/en/class.intldateformatter.php

    Should you need to use a different locale for displaying this time object, pass a locale string as the third parameter to this function.

    Examples

    $time = new Time('2014-04-20');
    $time->i18nFormat('de-DE');
    $time->i18nFormat(\IntlDateFormatter::FULL, 'de-DE');

    You can control the default locale used through DateTime::setDefaultLocale(). If empty, the default will be taken from the intl.default_locale ini config.

  • isEndOfDay() public

    Returns whether time is end of day.

    Compares against 23:59:59, ignoring microseconds.

  • isMidday() public

    Returns whether time is midday.

  • isMidnight() public

    Returns whether time is midnight.

  • isStartOfDay() public

    Returns whether time is start of day.

  • jsonSerialize() public

    Returns a string that should be serialized when converting this object to JSON

  • lessThan() public

    Returns whether time is less than target time.

  • lessThanOrEquals() public

    Returns whether time is less than or equal to target time.

  • max() public

    Returns the larger of this instance and the other.

  • midnight() public static

    Returns instance set to midnight.

  • min() public

    Returns the smaller of this instance and the other.

  • mod() protected static
  • modify() public

    Applies a date/time modifier string.

    Only time-component modifiers are accepted: combinations of signed integers followed by hour(s), minute(s), second(s), or microsecond(s). Date components (day, week, month, year) are not allowed and will throw. The result wraps around midnight.

  • nice() public

    Returns a nicely formatted date string for this object.

    The format to be used is stored in the static property Time::$niceFormat.

  • noon() public static

    Returns instance set to noon.

  • now() public static

    Returns instance set to server time.

  • parse() public static

    Copies time from onther instance or from string in the format HH[:.]mm or HH[:.]mm[:.]ss.u

    Defaults to server time.

  • parseString() protected static
  • parseTime() public static

    Returns a new Time object after parsing the provided $time string based on the passed or configured date time format. This method is locale dependent, Any string passed to this function will be interpreted as a locale dependent string.

    When no $format is provided, the IntlDateFormatter::SHORT format will be used.

    If it was impossible to parse the provided time, null will be returned.

    Example:

     $time = Time::parseTime('11:23pm');
  • processDateTime() protected static

    Returns a new Time object after parsing the provided time string based on the passed or configured date time format. This method is locale dependent, Any string that is passed to this function will be interpreted as a locale dependent string.

    Unlike DateTime, the time zone of the returned instance is always converted to $tz (default time zone if null) even if the $time string specified a time zone. This is a limitation of IntlDateFormatter.

    If it was impossible to parse the provided time, null will be returned.

    Example:

     $time = Time::parseDateTime('10/13/2013 12:54am');
     $time = Time::parseDateTime('13 Oct, 2013 13:54', 'dd MMM, y H:mm');
     $time = Time::parseDateTime('10/10/2015', [IntlDateFormatter::SHORT, IntlDateFormatter::NONE]);
  • resetToStringFormat() public static

    Resets the format used to the default when converting an instance of this type to a string

  • secondsSinceMidnight() public

    Returns the number of whole seconds since midnight.

  • setHours() public

    Set clock hours.

  • setJsonEncodeFormat() public static

    Sets the default format used when converting this object to JSON

    The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details)

    Alternatively, the format can provide a callback. In this case, the callback can receive this object and return a formatted string.

  • setMicroseconds() public

    Sets clock microseconds.

  • setMinutes() public

    Set clock minutes.

  • setSeconds() public

    Set clock seconds.

  • setTime() public

    Sets clock time.

  • setToStringFormat() public static

    Sets the default format used when type converting instances of this type to string

    The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details)

  • startOfHour() public

    Resets time to the start of the current hour.

  • subHours() public

    Returns a new instance with the given number of hours subtracted.

    Wraps around midnight like {@see self::addHours()}.

  • subMinutes() public

    Returns a new instance with the given number of minutes subtracted.

    Wraps around midnight like {@see self::addHours()}.

  • subSeconds() public

    Returns a new instance with the given number of seconds subtracted.

    Wraps around midnight like {@see self::addHours()}.

  • toArray() public

    Returns the time as an associative array.

  • toDateTimeImmutable() public

    Returns an DateTimeImmutable instance set to this clock time.

  • toNative() public

    Returns an DateTimeImmutable instance set to this clock time.

    Alias of toDateTimeImmutable().

  • withTicks() protected

    Returns a clone with the given absolute tick value.

Method Detail

__construct() ¶ public

__construct(Cake\Chronos\ChronosTime|DateTimeInterface|string|null $time = null, DateTimeZone|string|null $timezone = null)

Copies time from onther instance or from time string in the format HH[:.]mm or HH[:.]mm[:.]ss.u.

Defaults to server time.

Parameters
Cake\Chronos\ChronosTime|DateTimeInterface|string|null $time optional

Time

DateTimeZone|string|null $timezone optional

The timezone to use for now

__toString() ¶ public

__toString(): string

Format the instance as a string using the set format

Returns
string

addHours() ¶ public

addHours(int $value): static

Returns a new instance with the given number of hours added.

Arithmetic wraps around midnight: adding 2 hours to 23:00:00 yields 01:00:00; subtracting 2 hours from 00:00:00 yields 22:00:00.

Parameters
int $value

Hours to add

Returns
static

addMinutes() ¶ public

addMinutes(int $value): static

Returns a new instance with the given number of minutes added.

Wraps around midnight like {@see self::addHours()}.

Parameters
int $value

Minutes to add

Returns
static

addSeconds() ¶ public

addSeconds(int $value): static

Returns a new instance with the given number of seconds added.

Wraps around midnight like {@see self::addHours()}.

Parameters
int $value

Seconds to add

Returns
static

addTicks() ¶ protected

addTicks(int $delta): static

Adds a tick (microsecond) delta and wraps into [0, TICKS_PER_DAY).

Parameters
int $delta

Delta to add

Returns
static

between() ¶ public

between(Cake\Chronos\ChronosTime $start, Cake\Chronos\ChronosTime $end, bool $equals = true): bool

Returns whether time is between time range.

Parameters
Cake\Chronos\ChronosTime $start

Start of target range

Cake\Chronos\ChronosTime $end

End of target range

bool $equals optional

Whether to include the beginning and end of range

Returns
bool

closest() ¶ public

closest(Cake\Chronos\ChronosTime $first, Cake\Chronos\ChronosTime $second, Cake\Chronos\ChronosTime ...$others): static

Returns the ChronosTime closest to this instance.

Parameters
Cake\Chronos\ChronosTime $first

First candidate

Cake\Chronos\ChronosTime $second

Second candidate

Cake\Chronos\ChronosTime ...$others

Additional candidates

Returns
static

diff() ¶ public

diff(Cake\Chronos\ChronosTime $target, bool $absolute = false): DateInterval

Returns the difference between this time and a target time as a DateInterval.

Matches the signature of DateTimeInterface::diff() — defaults to a signed interval. Pass $absolute = true to drop the sign.

Parameters
Cake\Chronos\ChronosTime $target

Target time

bool $absolute optional

Whether to return an absolute interval

Returns
DateInterval

diffInHours() ¶ public

diffInHours(Cake\Chronos\ChronosTime|null $other = null, bool $absolute = true): int

Returns the difference in whole hours between this time and another.

Parameters
Cake\Chronos\ChronosTime|null $other optional

Target time, defaults to now

bool $absolute optional

Whether to return an absolute value

Returns
int

diffInMinutes() ¶ public

diffInMinutes(Cake\Chronos\ChronosTime|null $other = null, bool $absolute = true): int

Returns the difference in whole minutes between this time and another.

Parameters
Cake\Chronos\ChronosTime|null $other optional

Target time, defaults to now

bool $absolute optional

Whether to return an absolute value

Returns
int

diffInSeconds() ¶ public

diffInSeconds(Cake\Chronos\ChronosTime|null $other = null, bool $absolute = true): int

Returns the difference in whole seconds between this time and another.

Parameters
Cake\Chronos\ChronosTime|null $other optional

Target time, defaults to now

bool $absolute optional

Whether to return an absolute value

Returns
int

diffInTicks() ¶ protected

diffInTicks(Cake\Chronos\ChronosTime|null $other, bool $absolute): int
Parameters
Cake\Chronos\ChronosTime|null $other

Target time, defaults to now

bool $absolute

Whether to return an absolute value

Returns
int

endOfDay() ¶ public static

endOfDay(bool $microseconds = false): static

Returns instance set to end of day - either 23:59:59 or 23:59:59.999999 if $microseconds is true

Parameters
bool $microseconds optional

Whether to set microseconds or not

Returns
static

endOfHour() ¶ public

endOfHour(): static

Sets time to the end of the current hour.

Returns
static

equals() ¶ public

equals(Cake\Chronos\ChronosTime $target): bool

Returns whether time is equal to target time.

Parameters
Cake\Chronos\ChronosTime $target

Target time

Returns
bool

farthest() ¶ public

farthest(Cake\Chronos\ChronosTime $first, Cake\Chronos\ChronosTime $second, Cake\Chronos\ChronosTime ...$others): static

Returns the ChronosTime farthest from this instance.

Parameters
Cake\Chronos\ChronosTime $first

First candidate

Cake\Chronos\ChronosTime $second

Second candidate

Cake\Chronos\ChronosTime ...$others

Additional candidates

Returns
static

format() ¶ public

format(string $format): string

Formats string using the same syntax as DateTimeImmutable::format().

As this uses DateTimeImmutable::format() to format the string, non-time formatters will still be interpreted. Be sure to escape those characters first.

Parameters
string $format

Format string

Returns
string

formatObject() ¶ protected

formatObject(DateTimeInterface $date, array<int>|string $format, string|null $locale): string

Returns a translated and localized date string. Implements what IntlDateFormatter::formatObject() is in PHP 5.5+

Parameters
DateTimeInterface $date

Date.

array<int>|string $format

Format.

string|null $locale

The locale name in which the date should be displayed.

Returns
string

getHours() ¶ public

getHours(): int

Returns clock hours.

Returns
int

getMicroseconds() ¶ public

getMicroseconds(): int

Returns clock microseconds.

Returns
int

getMinutes() ¶ public

getMinutes(): int

Returns clock minutes.

Returns
int

getSeconds() ¶ public

getSeconds(): int

Return clock seconds.

Returns
int

greaterThan() ¶ public

greaterThan(Cake\Chronos\ChronosTime $target): bool

Returns whether time is greater than target time.

Parameters
Cake\Chronos\ChronosTime $target

Target time

Returns
bool

greaterThanOrEquals() ¶ public

greaterThanOrEquals(Cake\Chronos\ChronosTime $target): bool

Returns whether time is greater than or equal to target time.

Parameters
Cake\Chronos\ChronosTime $target

Target time

Returns
bool

i18nFormat() ¶ public

i18nFormat(string|int|null $format = null, string|null $locale = null): string|int

Returns a formatted string for this time object using the preferred format and language for the specified locale.

It is possible to specify the desired format for the string to be displayed. You can either pass IntlDateFormatter constants as the first argument of this function, or pass a full ICU date formatting string as specified in the following resource: https://unicode-org.github.io/icu/userguide/format_parse/datetime/#datetime-format-syntax.

Examples

$time = new Time('23:10:10');
$time->i18nFormat();
$time->i18nFormat(\IntlDateFormatter::FULL);
$time->i18nFormat("HH':'mm':'ss");

You can control the default format used through Time::setToStringFormat().

You can read about the available IntlDateFormatter constants at https://secure.php.net/manual/en/class.intldateformatter.php

Should you need to use a different locale for displaying this time object, pass a locale string as the third parameter to this function.

Examples

$time = new Time('2014-04-20');
$time->i18nFormat('de-DE');
$time->i18nFormat(\IntlDateFormatter::FULL, 'de-DE');

You can control the default locale used through DateTime::setDefaultLocale(). If empty, the default will be taken from the intl.default_locale ini config.

Parameters
string|int|null $format optional

Format string.

string|null $locale optional

The locale name in which the time should be displayed (e.g. pt-BR)

Returns
string|int

Formatted and translated time string

isEndOfDay() ¶ public

isEndOfDay(): bool

Returns whether time is end of day.

Compares against 23:59:59, ignoring microseconds.

Returns
bool

isMidday() ¶ public

isMidday(): bool

Returns whether time is midday.

Returns
bool

isMidnight() ¶ public

isMidnight(): bool

Returns whether time is midnight.

Returns
bool

isStartOfDay() ¶ public

isStartOfDay(): bool

Returns whether time is start of day.

Returns
bool

jsonSerialize() ¶ public

jsonSerialize(): string|int

Returns a string that should be serialized when converting this object to JSON

Returns
string|int

lessThan() ¶ public

lessThan(Cake\Chronos\ChronosTime $target): bool

Returns whether time is less than target time.

Parameters
Cake\Chronos\ChronosTime $target

Target time

Returns
bool

lessThanOrEquals() ¶ public

lessThanOrEquals(Cake\Chronos\ChronosTime $target): bool

Returns whether time is less than or equal to target time.

Parameters
Cake\Chronos\ChronosTime $target

Target time

Returns
bool

max() ¶ public

max(Cake\Chronos\ChronosTime|null $other = null): static

Returns the larger of this instance and the other.

Parameters
Cake\Chronos\ChronosTime|null $other optional

Target time, defaults to now

Returns
static

midnight() ¶ public static

midnight(): static

Returns instance set to midnight.

Returns
static

min() ¶ public

min(Cake\Chronos\ChronosTime|null $other = null): static

Returns the smaller of this instance and the other.

Parameters
Cake\Chronos\ChronosTime|null $other optional

Target time, defaults to now

Returns
static

mod() ¶ protected static

mod(int $a, int $b): int
Parameters
int $a

Right side

int $b
Returns
int

modify() ¶ public

modify(string $modifier): static

Applies a date/time modifier string.

Only time-component modifiers are accepted: combinations of signed integers followed by hour(s), minute(s), second(s), or microsecond(s). Date components (day, week, month, year) are not allowed and will throw. The result wraps around midnight.

Parameters
string $modifier

Modifier string (e.g. +2 hours, -30 minutes)

Returns
static
Throws
InvalidArgumentException
When the modifier is invalid or contains date units.

nice() ¶ public

nice(string|null $locale = null): string

Returns a nicely formatted date string for this object.

The format to be used is stored in the static property Time::$niceFormat.

Parameters
string|null $locale optional

The locale name in which the date should be displayed (e.g. pt-BR)

Returns
string

Formatted date string

noon() ¶ public static

noon(): static

Returns instance set to noon.

Returns
static

now() ¶ public static

now(DateTimeZone|string|null $timezone = null): static

Returns instance set to server time.

Parameters
DateTimeZone|string|null $timezone optional

The timezone to use for now

Returns
static

parse() ¶ public static

parse(Cake\Chronos\ChronosTime|DateTimeInterface|string $time = null, DateTimeZone|string|null $timezone = null): static

Copies time from onther instance or from string in the format HH[:.]mm or HH[:.]mm[:.]ss.u

Defaults to server time.

Parameters
Cake\Chronos\ChronosTime|DateTimeInterface|string $time optional

Time

DateTimeZone|string|null $timezone optional

The timezone to use for now

Returns
static

parseString() ¶ protected static

parseString(string $time): int
Parameters
string $time

Time string in the format HH[:.]mm or HH[:.]mm[:.]ss.u

Returns
int

parseTime() ¶ public static

parseTime(string $time, string|int|null $format = null): static|null

Returns a new Time object after parsing the provided $time string based on the passed or configured date time format. This method is locale dependent, Any string passed to this function will be interpreted as a locale dependent string.

When no $format is provided, the IntlDateFormatter::SHORT format will be used.

If it was impossible to parse the provided time, null will be returned.

Example:

 $time = Time::parseTime('11:23pm');
Parameters
string $time

The time string to parse.

string|int|null $format optional

Any format accepted by IntlDateFormatter.

Returns
static|null

processDateTime() ¶ protected static

processDateTime(string $time, array<int>|string $format, DateTimeZone|string|null $tz = null): static|null

Returns a new Time object after parsing the provided time string based on the passed or configured date time format. This method is locale dependent, Any string that is passed to this function will be interpreted as a locale dependent string.

Unlike DateTime, the time zone of the returned instance is always converted to $tz (default time zone if null) even if the $time string specified a time zone. This is a limitation of IntlDateFormatter.

If it was impossible to parse the provided time, null will be returned.

Example:

 $time = Time::parseDateTime('10/13/2013 12:54am');
 $time = Time::parseDateTime('13 Oct, 2013 13:54', 'dd MMM, y H:mm');
 $time = Time::parseDateTime('10/10/2015', [IntlDateFormatter::SHORT, IntlDateFormatter::NONE]);
Parameters
string $time

The time string to parse.

array<int>|string $format

Any format accepted by IntlDateFormatter.

DateTimeZone|string|null $tz optional

The timezone for the instance

Returns
static|null

resetToStringFormat() ¶ public static

resetToStringFormat(): void

Resets the format used to the default when converting an instance of this type to a string

Returns
void

secondsSinceMidnight() ¶ public

secondsSinceMidnight(): int

Returns the number of whole seconds since midnight.

Returns
int

setHours() ¶ public

setHours(int $hours): static

Set clock hours.

Parameters
int $hours

Clock hours

Returns
static

setJsonEncodeFormat() ¶ public static

setJsonEncodeFormat(Closure|string|int $format): void

Sets the default format used when converting this object to JSON

The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details)

Alternatively, the format can provide a callback. In this case, the callback can receive this object and return a formatted string.

Parameters
Closure|string|int $format

Format.

Returns
void
See Also
\Cake\I18n\Time::i18nFormat()

setMicroseconds() ¶ public

setMicroseconds(int $microseconds): static

Sets clock microseconds.

Parameters
int $microseconds

Clock microseconds

Returns
static

setMinutes() ¶ public

setMinutes(int $minutes): static

Set clock minutes.

Parameters
int $minutes

Clock minutes

Returns
static

setSeconds() ¶ public

setSeconds(int $seconds): static

Set clock seconds.

Parameters
int $seconds

Clock seconds

Returns
static

setTime() ¶ public

setTime(int $hours = 0, int $minutes = 0, int $seconds = 0, int $microseconds = 0): static

Sets clock time.

Parameters
int $hours optional

Clock hours

int $minutes optional

Clock minutes

int $seconds optional

Clock seconds

int $microseconds optional

Clock microseconds

Returns
static

setToStringFormat() ¶ public static

setToStringFormat(string|int $format): void

Sets the default format used when type converting instances of this type to string

The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details)

Parameters
string|int $format

Format.

Returns
void

startOfHour() ¶ public

startOfHour(): static

Resets time to the start of the current hour.

Returns
static

subHours() ¶ public

subHours(int $value): static

Returns a new instance with the given number of hours subtracted.

Wraps around midnight like {@see self::addHours()}.

Parameters
int $value

Hours to subtract

Returns
static

subMinutes() ¶ public

subMinutes(int $value): static

Returns a new instance with the given number of minutes subtracted.

Wraps around midnight like {@see self::addHours()}.

Parameters
int $value

Minutes to subtract

Returns
static

subSeconds() ¶ public

subSeconds(int $value): static

Returns a new instance with the given number of seconds subtracted.

Wraps around midnight like {@see self::addHours()}.

Parameters
int $value

Seconds to subtract

Returns
static

toArray() ¶ public

toArray(): array{hour: int, minute: int, second: int, microsecond: int}

Returns the time as an associative array.

Returns
array{hour: int, minute: int, second: int, microsecond: int}

toDateTimeImmutable() ¶ public

toDateTimeImmutable(DateTimeZone|string|null $timezone = null): DateTimeImmutable

Returns an DateTimeImmutable instance set to this clock time.

Parameters
DateTimeZone|string|null $timezone optional

Time zone the DateTimeImmutable instance will be in

Returns
DateTimeImmutable

toNative() ¶ public

toNative(DateTimeZone|string|null $timezone = null): DateTimeImmutable

Returns an DateTimeImmutable instance set to this clock time.

Alias of toDateTimeImmutable().

Parameters
DateTimeZone|string|null $timezone optional

Time zone the DateTimeImmutable instance will be in

Returns
DateTimeImmutable

withTicks() ¶ protected

withTicks(int $ticks): static

Returns a clone with the given absolute tick value.

Parameters
int $ticks

Ticks value

Returns
static

Property Detail

$formatters ¶ protected static

In-memory cache of date formatters

Type
array<string, \IntlDateFormatter>

$jsonEncodeFormat ¶ protected static

The format to use when converting this object to JSON.

The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details)

Type
Closure|string|int

$niceFormat ¶ public static

The format to use when formatting a time using Cake\I18n\Time::nice()

The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details)

Type
string|int

$ticks ¶ protected

Type
int

$toStringFormat ¶ protected static

The format to use when formatting a time using Cake\I18n\Time::i18nFormat() and __toString.

The format should be either the formatting constants from IntlDateFormatter as described in (https://secure.php.net/manual/en/class.intldateformatter.php) or a pattern as specified in (https://unicode-org.github.io/icu-docs/apidoc/released/icu4c/classSimpleDateFormat.html#details)

Type
array|string|int
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs