返回介绍

get_post_time()

发布于 2017-09-10 23:57:22 字数 2842 浏览 1328 评论 0 收藏 0

get_post_time( string $d = 'U',  bool $gmt = false,  int|WP_Post $post = null,  bool $translate = false )

Retrieve the time at which the post was written.


description


参数

$d

(string) (Optional) Format to use for retrieving the time the post was written. Either 'G', 'U', or php date format.

Default value: 'U'

$gmt

(bool) (Optional) Whether to retrieve the GMT time.

Default value: false

$post

(int|WP_Post) (Optional) WP_Post object or ID. Default is global $post object.

Default value: null

$translate

(bool) (Optional) Whether to translate the time string.

Default value: false


返回值

(string|int|false) Formatted date string or Unix timestamp if $id is 'U' or 'G'. False on failure.


源代码

File: wp-includes/general-template.php

function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
	$post = get_post($post);

	if ( ! $post ) {
		return false;
	}

	if ( $gmt )
		$time = $post->post_date_gmt;
	else
		$time = $post->post_date;

	$time = mysql2date($d, $time, $translate);

	/**
	 * Filters the localized time a post was written.
	 *
	 * @since 2.6.0
	 *
	 * @param string $time The formatted time.
	 * @param string $d    Format to use for retrieving the time the post was written.
	 *                     Accepts 'G', 'U', or php date format. Default 'U'.
	 * @param bool   $gmt  Whether to retrieve the GMT time. Default false.
	 */
	return apply_filters( 'get_post_time', $time, $d, $gmt );
}

更新日志

Versiondescription
2.0.0Introduced.

相关函数

Uses

  • wp-includes/general-template.php: get_post_time
  • wp-includes/functions.php: mysql2date()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: get_post()

Used By

  • wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::column_date()
  • wp-admin/includes/class-wp-media-list-table.php: WP_Media_List_Table::column_date()
  • wp-admin/includes/export.php: export_wp()
  • wp-includes/general-template.php: get_the_time()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文