返回介绍

get_comment_time()

发布于 2017-09-10 23:08:49 字数 3301 浏览 1074 评论 0 收藏 0

get_comment_time( string $d = '',  bool $gmt = false,  bool $translate = true )

Retrieve the comment time of the current comment.


description


参数

$d

(string) (Optional) The format of the time. Default user's settings.

Default value: ''

$gmt

(bool) (Optional) Whether to use the GMT date.

Default value: false

$translate

(bool) (Optional) Whether to translate the time (for use in feeds).

Default value: true


返回值

(string) The formatted time.


源代码

File: wp-includes/comment-template.php

function get_comment_time( $d = '', $gmt = false, $translate = true ) {
	$comment = get_comment();

	$comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;
	if ( '' == $d )
		$date = mysql2date(get_option('time_format'), $comment_date, $translate);
	else
		$date = mysql2date($d, $comment_date, $translate);

	/**
	 * Filters the returned comment time.
	 *
	 * @since 1.5.0
	 *
	 * @param string|int $date      The comment time, formatted as a date string or Unix timestamp.
	 * @param string     $d         Date format.
	 * @param bool       $gmt       Whether the GMT date is in use.
	 * @param bool       $translate Whether the time is translated.
	 * @param WP_Comment $comment   The comment object.
	 */
	return apply_filters( 'get_comment_time', $date, $d, $gmt, $translate, $comment );
}

更新日志

Versiondescription
1.5.0Introduced.

相关函数

Uses

  • wp-includes/functions.php: mysql2date()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/option.php: get_option()
  • wp-includes/comment-template.php: get_comment_time
  • wp-includes/comment.php: get_comment()

Used By

  • wp-includes/class-walker-comment.php: Walker_Comment::comment()
  • wp-includes/class-walker-comment.php: Walker_Comment::html5_comment()
  • wp-includes/comment-template.php: comment_time()

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: 0You must log in to vote on the helpfulness of this note Contributed by thelittlemercoder

    Examples of Different Time Formats

    
    // Prints something like: 03:08:46 PM
    echo get_comment_time( 'h:i:s A' );
    
    // Prints something like: 3:08:46 pm
    echo get_comment_time( 'g:i:s a' );
    
    // Prints 24 hour time, something like: 0800
    echo get_comment_time( 'Hi' );
    
    // Prints 24 hour time, something like: 800
    echo get_comment_time( 'Gi' );
    

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

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

发布评论

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