WordPress at a glance

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().

Works based on: get_the_time()
Hooks from function:
Return

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

#1 Output the time of publication of the post

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

#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>

#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>

Code of the_time: wp-includes/general-template.php VER 4.9.8

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

Related Functions

From tag: WP Loop

More from tag: date time

More from category: Posts, pages...

More from Template Tags: Posts, Pages, ...

No comments
    Hello, !     Log In . Register