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

返回介绍

get_comment_time()

发布于 2017-09-10 字数3303 浏览 973 评论 0

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

Retrieve the comment time of the current comment.


描述


参数

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

更新日志

Version 描述
1.5.0 Introduced.

相关函数

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' );
    

上一篇:get_comment_text()

下一篇:get_comment_to_edit()

发布评论

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

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