|
Size: | 14303 |
Storage flags: | no_autoload,compress/gzip (26%) |
The DateFormat view helper can be used to simplify rendering of localized date/time values. It acts as a wrapper for the IntlDateFormatter class within the Internationalization extension (Intl).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | // Within your view
// Date and Time
echo $this->dateFormat(
new DateTime(),
IntlDateFormatter::MEDIUM, // date
IntlDateFormatter::MEDIUM, // time
"en_US"
);
// This returns: "Jul 2, 2012 6:44:03 PM"
// Date Only
echo $this->dateFormat(
new DateTime(),
IntlDateFormatter::LONG, // date
IntlDateFormatter::NONE, // time
"en_US"
);
// This returns: "July 2, 2012"
// Time Only
echo $this->dateFormat(
new DateTime(),
IntlDateFormatter::NONE, // date
IntlDateFormatter::SHORT, // time
"en_US"
);
// This returns: "6:44 PM"
|
Parameters: |
|
---|
The $locale option can be set prior to formatting with the setLocale() method and will be applied each time the helper is used.
By default, the system’s default timezone will be used when formatting. This overrides any timezone that may be set inside a DateTime object. To change the timezone when formatting, use the setTimezone method.
1 2 3 4 5 | // Within your view
$this->plugin("dateFormat")->setTimezone("America/New_York")->setLocale("en_US");
echo $this->dateFormat(new DateTime(), IntlDateFormatter::MEDIUM); // "Jul 2, 2012"
echo $this->dateFormat(new DateTime(), IntlDateFormatter::SHORT); // "7/2/12"
|
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.