the_time()WP 0.71

Display the time (date) at which the post was written in the specified format.

This function must be used inside the Loop of WordPress.

The function is identical to the function: the_date().

Hooks from the function

Return

null. Nothing (null). The result is displayed.

Usage

<?php the_time( $d ); ?>
$d(string)
Date format (in PHP syntax). For example, j F Y will print "12 December 2010". More information about date formatting in PHP.
Default: '' (time_format option)

Examples

0

#1 Output the time of publication of the post

This entry was posted: <?php the_time(); ?>
0

#2 Time in "24 hour" and "AM/PM" formats

Let's output the time at which the post was written in the format "24 hours" (23: 12):

<p>Publish time: <?php the_time('G:i'); ?></p>

If you want to output in AM/PM format:

<p>Publish time: <?php the_time('g:i a'); ?></p>
0

#3 Display the date (not time)

the_time() in addition to the time can display the date, you only need to specify a format:

<div><?php the_time('j F Y'); ?></div>

Changelog

Since 0.71 Introduced.

the_time() code WP 6.4.3

function the_time( $format = '' ) {
	/**
	 * Filters the time a post was written for display.
	 *
	 * @since 0.71
	 *
	 * @param string $get_the_time The formatted time.
	 * @param string $format       Format to use for retrieving the time the post
	 *                             was written. Accepts 'G', 'U', or PHP date format.
	 */
	echo apply_filters( 'the_time', get_the_time( $format ), $format );
}