wp_date
函数
wp_date ( $format, $timestamp = null, $timezone = null )
- 参数
-
-
(string)
$format
PHP date format.- Required: 是
-
(int)
$timestamp
Optional. Unix timestamp. Defaults to current time.- Required: 否
- Default: null
-
(DateTimeZone)
$timezone
Optional. Timezone to output result in. Defaults to timezone from site settings.- Required: 否
- Default: null
-
(string)
- 返回值
-
- (string|false) The date, translated if locale specifies it. False on invalid timestamp input.
- 定义位置
-
-
wp-includes/functions.php
, line 240
-
wp-includes/functions.php
- 引入
- 5.3.0
- 弃用
- –
Retrieves the date, in localized format.
This is a newer function, intended to replace `date_i18n()` without legacy quirks in it.
Note that, unlike `date_i18n()`, this function accepts a true Unix timestamp, not summed
with timezone offset.
function wp_date( $format, $timestamp = null, $timezone = null ) { global $wp_locale; if ( null === $timestamp ) { $timestamp = time(); } elseif ( ! is_numeric( $timestamp ) ) { return false; } if ( ! $timezone ) { $timezone = wp_timezone(); } $datetime = date_create( '@' . $timestamp ); $datetime->setTimezone( $timezone ); if ( empty( $wp_locale->month ) || empty( $wp_locale->weekday ) ) { $date = $datetime->format( $format ); } else { // We need to unpack shorthand `r` format because it has parts that might be localized. $format = preg_replace( '/(?get_month( $datetime->format( 'm' ) ); $weekday = $wp_locale->get_weekday( $datetime->format( 'w' ) ); for ( $i = 0; $i get_weekday_abbrev( $weekday ), 'A..Za..z' ); break; case 'F': $new_format .= addcslashes( $month, 'A..Za..z' ); break; case 'l': $new_format .= addcslashes( $weekday, 'A..Za..z' ); break; case 'M': $new_format .= addcslashes( $wp_locale->get_month_abbrev( $month ), 'A..Za..z' ); break; case 'a': $new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'a' ) ), 'A..Za..z' ); break; case 'A': $new_format .= addcslashes( $wp_locale->get_meridiem( $datetime->format( 'A' ) ), 'A..Za..z' ); break; case '': $new_format .= $format[ $i ]; // If character follows a slash, we add it without translating. if ( $i format( $new_format ); $date = wp_maybe_decline_date( $date, $format ); } /** * Filters the date formatted based on the locale. * * @since 5.3.0 * * @param string $date Formatted date string. * @param string $format Format to display the date. * @param int $timestamp Unix timestamp. * @param DateTimeZone $timezone Timezone. */ $date = apply_filters( 'wp_date', $date, $format, $timestamp, $timezone ); return $date; }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。