Using WordPress ‘get_comment_time()’ PHP function

The get_comment_time() WordPress PHP function retrieves the comment time of the current comment.

Usage

get_comment_time( $format, $gmt, $translate, $comment_id )

Example:

echo get_comment_time( 'h:i:s A' );

Output:

03:08:46 PM

Parameters

  • $format (string) Optional: PHP date format. Defaults to the ‘time_format’ option. Default: ”
  • $gmt (bool) Optional: Whether to use the GMT date. Default: false
  • $translate (bool) Optional: Whether to translate the time (for use in feeds). Default: true
  • $comment_id (int|WP_Comment) Optional: WP_Comment or ID of the comment for which to get the time. Default current comment.

More information

See WordPress Developer Resources: get_comment_time()

Examples

Display comment time in 12-hour format

This example retrieves the comment time in a 12-hour format with AM/PM.

echo get_comment_time( 'h:i:s A' );

Display comment time in lowercase

This example retrieves the comment time in a 12-hour format with lowercase am/pm.

echo get_comment_time( 'g:i:s a' );

Display comment time in 24-hour format

This example retrieves the comment time in a 24-hour format without colon separator.

echo get_comment_time( 'Hi' );

Display comment time in 24-hour format without leading zero

This example retrieves the comment time in a 24-hour format without a leading zero and without colon separator.

echo get_comment_time( 'Gi' );

Display GMT comment time

This example retrieves the comment time in GMT timezone.

echo get_comment_time( 'h:i:s A', true );