date_i18n
云策文档标注
概述
date_i18n 是一个 WordPress 过滤器,用于基于本地化设置格式化日期字符串。它允许开发者修改日期显示格式,支持时间戳和时区参数。
关键要点
- 过滤器名称:date_i18n,用于修改本地化日期格式。
- 参数:包括格式化后的日期字符串、格式字符串、时间戳(可包含时区偏移)和是否使用 GMT 时区。
- 应用场景:常用于 date_i18n() 函数中,以自定义日期输出。
- 版本历史:自 WordPress 2.8.0 引入。
代码示例
echo date_i18n( __( 'M j, Y @ G:i', 'textdomain' ), strtotime( 'now' ), true );注意事项
- 建议使用 time() 替代 strtotime('now') 以获取实际时间戳,提高性能。
原文内容
Filters the date formatted based on the locale.
Parameters
$datestring-
Formatted date string.
$formatstring-
Format to display the date.
$timestampint-
A sum of Unix timestamp and timezone offset in seconds.
Might be without offset if input omitted timestamp but requested GMT. $gmtbool-
Whether to use GMT timezone. Only applies if timestamp was not provided.
Source
$date = apply_filters( 'date_i18n', $date, $format, $timestamp, $gmt );
Changelog
| Version | Description |
|---|---|
| 2.8.0 | Introduced. |
Skip to note 2 content
thejaydip
Basic Example
echo date_i18n( __( 'M j, Y @ G:i', 'textdomain' ), strtotime( 'now' ), true );