get_comment_time()WP 1.5.0

Retrieve the comment time of the current comment.

Used By: comment_time()
Hooks from the function

Return

String. The formatted time.

Usage

get_comment_time( $format, $gmt, $translate, $comment_id );
$format(string)
PHP date format. option.
Default: 'time_format'
$gmt(true|false)
Whether to use the GMT date.
Default: false
$translate(true|false)
Whether to translate the time (for use in feeds).
Default: true
$comment_id(int|WP_Comment)
WP_Comment or ID of the comment for which to get the time.
Default: current comment

Examples

0

#1 Examples of Different Time Formats

echo get_comment_time( 'h:i:s A' ); // 03:08:46 PM

echo get_comment_time( 'g:i:s a' ); // 3:08:46 pm

echo get_comment_time( 'Hi' ); // 0800 (24 hour time)

echo get_comment_time( 'Gi' ); // 800 (24 hour time)
0

#2 Publication time of the current comment

In the format 22:04:11. The code should be used inside the comment loop, usually the built-in function specified in the callback parameter of the wp_list_comments().

<p>Comment publishing time: <?php get_comment_time('H:i:s'); ?></p>

Changelog

Since 1.5.0 Introduced.
Since 6.2.0 Added the $comment_id parameter.

get_comment_time() code WP 6.5.2

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

	if ( null === $comment ) {
		return '';
	}

	$comment_date = $gmt ? $comment->comment_date_gmt : $comment->comment_date;

	$_format = ! empty( $format ) ? $format : get_option( 'time_format' );

	$comment_time = mysql2date( $_format, $comment_date, $translate );

	/**
	 * Filters the returned comment time.
	 *
	 * @since 1.5.0
	 *
	 * @param string|int $comment_time The comment time, formatted as a date string or Unix timestamp.
	 * @param string     $format       PHP 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', $comment_time, $format, $gmt, $translate, $comment );
}