Example 1 — Default time
Print the time in the site format.
<span class="time"><?php comment_time(); ?></span> How It Works
- No format is given.
- WordPress uses the time format from your settings.
- The time is printed as plain text.

In WordPress, comment_time() prints the time when a comment was posted.
By default it uses the time format from Settings → General. You can pass a PHP time format to change it.
Call it with no format for the site format, or pass a PHP time format.
comment_time();
comment_time( 'H:i' );
comment_time( 'g:i a', 15 ); | Call | What it does |
|---|---|
comment_time() | Prints the time in the site's time format. |
comment_time( 'H:i' ) | Prints the time in 24-hour format. |
comment_time( 'g:i a', 15 ) | Prints the time of comment 15. |
Use comment_date() to print the date of the comment.
comment_time( string $format = '', int|WP_Comment $comment_id = 0 ): void | Parameter | Description |
|---|---|
$format | Optional. A PHP time format. If empty, WordPress uses the time_format option. |
$comment_id | Optional. A comment ID or WP_Comment object. Default is the current comment. Added in WordPress 6.2. |
| Return Value | Description |
|---|---|
| void | Nothing is returned. The function prints the time. |
Three short theme examples. Each one has a sample output.
Print the time in the site format.
<span class="time"><?php comment_time(); ?></span> Print the time in 24-hour format.
<span class="time"><?php comment_time( 'H:i' ); ?></span> H is the hour in 24-hour format.i is the minutes.Print the date and the time together.
<p><?php comment_date(); ?> at <?php comment_time(); ?></p> comment_date() prints the date.comment_time() prints the time.at is your own text.Print the type of the current comment: Comment, Trackback, or Pingback.
11 people found this page helpful