get_post_time() - WordPress 函数参考中文文档

返回介绍

get_post_time()

发布于 2017-09-10 字数2844 浏览 1049 评论 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.


描述


参数

$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 );
}

更新日志

Version 描述
2.0.0 Introduced.

相关函数

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!