IntlDateFormatter::format() - IntlDateFormatter类
IntlDateFormatter::format()
datefmt_format
(PHP 5 >= 5.3.0, PHP 7, PECL intl >= 1.0.0)
Format the date/time value as a string
说明
面向对象风格publicIntlDateFormatter::format(mixed $value): string过程化风格
datefmt_format(IntlDateFormatter$fmt, mixed $value): string
Formats the time value as a string.
参数
$fmtThe date formatter resource.
$valueValue to format. This may be a DateTimeInterface object, an IntlCalendar object, a numeric type representing a(possibly fractional)number of seconds since epoch or an array in the format output by localtime().
If a DateTime or an IntlCalendar object is passed, its timezone is not considered. The object will be formatted using the formaterʼs configured timezone. If one wants to use the timezone of the object to be formatted,IntlDateFormatter::setTimeZone() must be called before with the objectʼs timezone. Alternatively, the static function IntlDateFormatter::formatObject() may be used instead.
返回值
The formatted string or, if an error occurred,FALSE
.
更新日志
版本 | 说明 |
---|---|
7.1.5 | Support for providing general DateTimeInterface objects to the$valueparameter was added. Formerly, only proper DateTime objects were supported. |
5.5.0/PECL 3.0.0 | Support for providing IntlCalendar objects to the$valueparameter was added. |
5.3.4 | Support for providing DateTime objects to the$valueparameter was added. |
范例
datefmt_format() example
OO example
以上例程会输出:
First Formatted output is Wednesday, December 31, 1969 4:00:00 PM PT Second Formatted output is Mittwoch, 31. Dezember 1969 16:00 Uhr GMT-08:00 First Formatted output with pattern is 12/31/1969 Second Formatted output with pattern is 12/31/1969
With IntlCalendar object
Example for PHP Version 5.3.2-1ubuntu4.9 (the prod server): When using $dateFormatter->format($date->getTimestamp()), you'll always get the formatted and localized string instead of a false.
It's important to note that a conversion of timezones will be made from the default timezone (date_default_timezone_set()) and the timezone you passed in the constructor (or datefmt_create()). If you are inserting the dates into your database as UTC time, make sure to set date_default_timezone_set to UTC as well (or any other timezone, but they need to be the same). Once you call ::format, you will get the converted time.
鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com
图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!