get_comment_date()通过ID获取一个评论的发布时间

目录

描述

Retrieve the comment date of the current comment.

get_comment_date() 描述

用法

<?php get_comment_date$d$comment_ID ); ?>

Parameters

$d

(string) (optional) Date format. If empty, it will default to get_option( 'date_format' ) (the format configured in the site's settings).

Default: Empty string

$comment_ID

(int) (optional) A comment ID. If empty, the current comment will be used.

Default: 0

Returns

(String) 

Formatted comment date.

Examples

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
<?php $d = "l, F jS, Y";$comment_date = get_comment_date( $d, $comment_ID );echo $comment_date;// This will output something similar to "Saturday, November 6th, 2010". ?>

Notes

get_comment_date() 用法

历史

get_comment_date() 历史

源文件

get_comment_date() 函数的代码位于 wp-includes/comment-template.php

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */
/**
 * Retrieve the comment date of the current comment.
 *
 * @since 1.5.0
 *
 * @param string $d          Optional. The format of the date. Default user's setting.
 * @param int    $comment_ID ID of the comment for which to get the date. Default current comment.
 * @return string The comment's date.
 */
function get_comment_date( $d = '', $comment_ID = 0 ) {
	$comment = get_comment( $comment_ID );
	if ( '' == $d )
		$date = mysql2date(get_option('date_format'), $comment->comment_date);
	else
		$date = mysql2date($d, $comment->comment_date);
	/**
	 * Filter the returned comment date.
	 *
	 * @since 1.5.0
	 *
	 * @param string|int $date    Formatted date string or Unix timestamp.
	 * @param string     $d       The format of the date.
	 * @param object     $comment The comment object.
	 */
	return apply_filters( 'get_comment_date', $date, $d, $comment );
}

get_comment_date() 源文件