CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Team
    • Issues (Github)
    • YouTube Channel
    • Get Involved
    • Bakery
    • Featured Resources
    • Newsletter
    • Certification
    • My CakePHP
    • CakeFest
    • Facebook
    • Twitter
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 3.8 Red Velvet API

  • Overview
  • Tree
  • Deprecated
  • Version:
    • 3.8
      • 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

  • Cake
    • Auth
      • Storage
    • Cache
      • Engine
    • Collection
      • Iterator
    • Command
    • Console
      • Exception
    • Controller
      • Component
      • Exception
    • Core
      • Configure
        • Engine
      • Exception
      • Retry
    • Database
      • Driver
      • Exception
      • Expression
      • Schema
      • Statement
      • Type
    • Datasource
      • Exception
    • Error
      • Middleware
    • Event
      • Decorator
    • Filesystem
    • Form
    • Http
      • Client
        • Adapter
        • Auth
      • Cookie
      • Exception
      • Middleware
      • Session
    • I18n
      • Formatter
      • Middleware
      • Parser
    • Log
      • Engine
    • Mailer
      • Exception
      • Transport
    • Network
      • Exception
    • ORM
      • Association
      • Behavior
        • Translate
      • Exception
      • Locator
      • Rule
    • Routing
      • Exception
      • Filter
      • Middleware
      • Route
    • Shell
      • Helper
      • Task
    • TestSuite
      • Fixture
      • Stub
    • Utility
      • Exception
    • Validation
    • View
      • Exception
      • Form
      • Helper
      • Widget
  • None

Classes

  • ChainMessagesLoader
  • Date
  • FrozenDate
  • FrozenTime
  • I18n
  • MessagesFileLoader
  • Number
  • PluralRules
  • Time
  • TranslatorRegistry

Traits

  • DateFormatTrait

Trait DateFormatTrait

Trait for date formatting methods shared by both Time & Date.

This trait expects that the implementing class define static::$_toStringFormat.

Direct Users

  • Cake\I18n\Date
  • Cake\I18n\FrozenDate
  • Cake\I18n\FrozenTime
  • Cake\I18n\Time
Namespace: Cake\I18n
Location: I18n/DateFormatTrait.php

Properties summary

  • $_formatters protected static
    IntlDateFormatter[]
    In-memory cache of date formatters
  • $_isDateInstance protected static
    boolean
    Caches whether or not this class is a subclass of a Date or MutableDate
  • $_jsonEncodeFormat protected static
    string|array|integer
    The format to use when when converting this object to json
  • $defaultLocale public static
    string
    The default locale to be used for displaying formatted date strings.

Method Summary

  • __debugInfo() public
    Returns the data that should be displayed when debugging this object
  • __toString() public
  • _formatObject() protected

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

  • diffFormatter() public static
    Get the difference formatter instance or overwrite the current one.
  • getDefaultLocale() public static
    Gets the default locale.
  • i18nFormat() public

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

  • jsonSerialize() public
    Returns a string that should be serialized when converting this object to json
  • nice() public
    Returns a nicely formatted date string for this object.
  • parseDate() public static

    Returns a new Time object after parsing the provided $date 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.

  • parseDateTime() 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 that is passed to this function will be interpreted as a locale dependent string.

  • 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 that is passed to this function will be interpreted as a locale dependent string.

  • resetToStringFormat() public static

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

  • setDefaultLocale() public static
    Sets the default locale.
  • setJsonEncodeFormat() public static
    Sets the default format used when converting this object to json
  • setToStringFormat() public static
    Sets the default format used when type converting instances of this type to string

Method Detail

__debugInfo() public ¶

__debugInfo( )

Returns the data that should be displayed when debugging this object

Returns
array

__toString() public ¶

__toString( )

_formatObject() protected ¶

_formatObject( DateTime $date , string|integer|array $format , string|null $locale )

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

Parameters
DateTime $date
Date.
string|integer|array $format
Format.
string|null $locale
The locale name in which the date should be displayed.
Returns
string

diffFormatter() public static ¶

diffFormatter( Cake\I18n\RelativeTimeFormatter|null $formatter = null )

Get the difference formatter instance or overwrite the current one.

Parameters
Cake\I18n\RelativeTimeFormatter|null $formatter optional null
The formatter instance when setting.
Returns
Cake\I18n\RelativeTimeFormatter
The formatter instance.

getDefaultLocale() public static ¶

getDefaultLocale( )

Gets the default locale.

Returns
string|null
The default locale string to be used or null.

i18nFormat() public ¶

i18nFormat( string|integer|null $format = null , string|DateTimeZone|null $timezone = null , string|null $locale = null )

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: http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details.

Additional to IntlDateFormatter constants and date formatting string you can use Time::UNIX_TIMESTAMP_FORMAT to get a unix timestamp

Examples

$time = new Time('2014-04-20 22:10');
$time->i18nFormat(); // outputs '4/20/14, 10:10 PM' for the en-US locale
$time->i18nFormat(\IntlDateFormatter::FULL); // Use the full date and time format
$time->i18nFormat([\IntlDateFormatter::FULL, \IntlDateFormatter::SHORT]); // Use full date but short time format
$time->i18nFormat('yyyy-MM-dd HH:mm:ss'); // outputs '2014-04-20 22:10'
$time->i18nFormat(Time::UNIX_TIMESTAMP_FORMAT); // outputs '1398031800'

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

If you need to display the date in a different timezone than the one being used for this Time object without altering its internal state, you can pass a timezone string or object as the second parameter.

Finally, 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 22:10');
$time->i18nFormat(null, null, 'de-DE');
$time->i18nFormat(\IntlDateFormatter::FULL, 'Europe/Berlin', 'de-DE');

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

Parameters
string|integer|null $format optional null
Format string.
string|DateTimeZone|null $timezone optional null

Timezone string or DateTimeZone object in which the date will be displayed. The timezone stored for this object will not be changed.

string|null $locale optional null
The locale name in which the date should be displayed (e.g. pt-BR)
Returns
string|integer
Formatted and translated date string

jsonSerialize() public ¶

jsonSerialize( )

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

Returns
string

nice() public ¶

nice( string|DateTimeZone|null $timezone = null , string|null $locale = null )

Returns a nicely formatted date string for this object.

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

Parameters
string|DateTimeZone|null $timezone optional null

Timezone string or DateTimeZone object in which the date will be displayed. The timezone stored for this object will not be changed.

string|null $locale optional null
The locale name in which the date should be displayed (e.g. pt-BR)
Returns
string
Formatted date string

parseDate() public static ¶

parseDate( string $date , string|integer|null $format = null )

Returns a new Time object after parsing the provided $date 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.

When no $format is provided, the wordFormat format will be used.

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

Example:

$time = Time::parseDate('10/13/2013');
 $time = Time::parseDate('13 Oct, 2013', 'dd MMM, y');
 $time = Time::parseDate('13 Oct, 2013', IntlDateFormatter::SHORT);
Parameters
string $date
The date string to parse.
string|integer|null $format optional null
Any format accepted by IntlDateFormatter.
Returns
Cake\I18n\DateFormatTrait|null

parseDateTime() public static ¶

parseDateTime( string $time , string|array|null $format = 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.

When no $format is provided, the toString format will be used.

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, -1]);
Parameters
string $time
The time string to parse.
string|array|null $format optional null
Any format accepted by IntlDateFormatter.
Returns
Cake\I18n\DateFormatTrait|null

parseTime() public static ¶

parseTime( string $time , string|integer|null $format = 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.

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|integer|null $format optional null
Any format accepted by IntlDateFormatter.
Returns
Cake\I18n\DateFormatTrait|null

resetToStringFormat() public static ¶

resetToStringFormat( )

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

setDefaultLocale() public static ¶

setDefaultLocale( string|null $locale = null )

Sets the default locale.

Parameters
string|null $locale optional null
The default locale string to be used or null.

setJsonEncodeFormat() public static ¶

setJsonEncodeFormat( string|array|integer $format )

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)

It is possible to provide an array of 2 constants. In this case, the first position will be used for formatting the date part of the object and the second position will be used to format the time part.

Parameters
string|array|integer $format
Format.
See
\Cake\I18n\Time::i18nFormat()

setToStringFormat() public static ¶

setToStringFormat( string|array|integer $format )

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 (http://www.icu-project.org/apiref/icu4c/classSimpleDateFormat.html#details)

It is possible to provide an array of 2 constants. In this case, the first position will be used for formatting the date part of the object and the second position will be used to format the time part.

Parameters
string|array|integer $format
Format.

Properties detail

$_formatters ¶

protected static IntlDateFormatter[]

In-memory cache of date formatters

[]

$_isDateInstance ¶

protected static boolean

Caches whether or not this class is a subclass of a Date or MutableDate

$_jsonEncodeFormat ¶

protected static string|array|integer

The format to use when 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)

It is possible to provide an array of 2 constants. In this case, the first position will be used for formatting the date part of the object and the second position will be used to format the time part.

See
\Cake\I18n\Time::i18nFormat()
"yyyy-MM-dd'T'HH':'mm':'ssxxx"

$defaultLocale ¶

public static string

The default locale to be used for displaying formatted date strings.

Deprecated
3.2.9 Use static::setDefaultLocale() and static::getDefaultLocale() instead.
Follow @CakePHP
#IRC
OpenHub
Rackspace
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Logos & Trademarks
  • Community
  • Team
  • Issues (Github)
  • YouTube Channel
  • Get Involved
  • Bakery
  • Featured Resources
  • Newsletter
  • Certification
  • My CakePHP
  • CakeFest
  • Facebook
  • Twitter
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs