diff --git a/src/Utility/Time.php b/src/Utility/Time.php index 5518ff033b8..261bc0aa14e 100644 --- a/src/Utility/Time.php +++ b/src/Utility/Time.php @@ -1,7 +1,5 @@ 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' + * }}} + * + * If you wish to control the default format to be used for this method, you can alter + * the value of the static `Time::$defaultLocale` variable and set it to one of the + * possible formats accepted by this function. + * + * You can read about the available IntlDateFormatter constants at + * http://www.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 * * {{{ - * Cake\Utility\Time::format('2012-02-15', '%m-%d-%Y'); // returns 02-15-2012 - * Cake\Utility\Time::format('2012-02-15 23:01:01', '%c'); // returns preferred date and time based on configured locale - * Cake\Utility\Time::format('0000-00-00', '%d-%m-%Y', 'N/A'); // return N/A becuase an invalid date was passed - * Cake\Utility\Time::format('2012-02-15 23:01:01', '%c', 'N/A', 'America/New_York'); // converts passed date to timezone + * $time = new Time('2014-04-20 22:10'); + * $time->i18nFormat(null, null, 'de-DE'); + * $time->i18nFormat(\IntlDateFormatter::FULL, 'Europe/Berlin', 'de-DE'); * }}} * - * @param string $format strftime format string. + * You can control the default locale to be used by setting the static variable + * `Time::$defaultLocale` to a valid locale string. If empty, the default will be + * taken from the `intl.default_locale` ini config. + * + * @param string|int $format * @param string|\DateTimeZone $timezone Timezone string or DateTimeZone object * in which the date will be displayed. The timezone stored for this object will not * be changed. * @param $locale The locale name in which the date should be displayed (e.g. pt-BR) * @return string Formatted and translated date string - * @link http://book.cakephp.org/2.0/en/core-libraries/helpers/time.html#TimeHelper::i18nFormat */ public function i18nFormat($format = null, $timezone = null, $locale = null) { $time = $this;