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

Retrieves the comment time of the current comment.


Parameters Parameters

$format

(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


Top ↑

Return Return

(string) The formatted time.


Top ↑

Source Source

File: wp-includes/comment-template.php

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

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

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

	$date = mysql2date( $_format, $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     $format    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, $format, $gmt, $translate, $comment );
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.5.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    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' );
    

You must log in before being able to contribute a note or feedback.