函数文档

comment_date()

💡 云策文档标注

概述

comment_date() 是一个 WordPress 函数,用于显示当前评论的日期。它基于 get_comment_date() 实现,支持自定义日期格式和指定评论 ID。

关键要点

  • 函数功能:显示当前评论的日期,可接受可选参数 $format(PHP 日期格式)和 $comment_id(评论 ID 或 WP_Comment 对象)。
  • 默认行为:如果不提供参数,使用 'date_format' 选项作为默认格式,并针对当前评论输出日期。
  • 相关函数:get_comment_date() 用于检索评论日期,而 comment_date() 直接输出。
  • 版本更新:从 WordPress 4.4.0 开始,$comment_id 参数可以接受 WP_Comment 对象。

代码示例

Comment posted on <?php comment_date('m-d-Y'); ?>

📄 原文内容

Displays the comment date of the current comment.

Parameters

$formatstringoptional
PHP date format. Defaults to the 'date_format' option.
$comment_idint|WP_Commentoptional
WP_Comment or ID of the comment for which to print the date.
Default current comment.

More Information

For the format of the date, see Formatting Date and Time.

Source

function comment_date( $format = '', $comment_id = 0 ) {
	echo get_comment_date( $format, $comment_id );
}

Changelog

Version Description
4.4.0 Added the ability for $comment_id to also accept a WP_Comment object.
0.71 Introduced.

User Contributed Notes