get_post_datetime()
get_post_datetime( int|WP_Post $post = null, string $field = ‘date’, string $source = ‘local’ )
以“DateTimeImmutable”对象实例检索发布后或修改后的时间。
Retrieve post published or modified time as a `DateTimeImmutable` object instance.
说明(Description)
对象将从WordPress设置设置为时区。
由于传统原因,此函数允许选择从数据库中的本地时间或UTC时间实例化。通常这对结果没有影响。但是,这些值可能在数据库中不同步,通常是因为时区设置更改。该参数确保在这种情况下能够再现向后兼容的行为。
参数(Parameters)
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
$post | (int | WP_Post) | 可选 | WP_Post object或ID。默认值为全局$Post object。 |
$field | (string) | 可选 | 从数据库中发布或修改要使用的时间。接受“日期”或“已修改”。 |
$source | (string) | 可选 | 从数据库使用的本地或UTC时间。接受“本地”或“gmt”。 |
返回(Return)
(DateTimeImmutable|false)成功时为时间对象,失败时为false。
源码(Source)
更新版本 | 源码位置 | 使用 | 被使用 |
---|---|---|---|
5.3.0 | wp-includes/general-template.php:2627 | 3 | 2 |
get_post_datetime() 为WP2原创文章,链接:https://www.wp2.cn/functions/get_post_datetime/