Ready to get started?Download WordPress


Function Reference/get the time



Returns the time of the current post for use in PHP. It does not display the time. To display the time of a post, use the_time(). This tag must be used within The Loop.


 <?php get_the_time$d$post ); ?> 


(string) (optional) The format used to display the time (and date). See Formatting Date and Time for other time and date formats.
Default: Time Format configured in Administration > Settings > General
(integer/object) (optional) post ID or object.
Default: null. global $post object

Return Values

Returns the time according to the default or specified time format.


Default Usage

Returns the time of the current post using the WordPress default format, and displays it using the PHP echo command.

<?php echo get_the_time(); ?>

Returns the time of the post with ID $post->ID in the WordPress default format.

<?php echo get_the_time('', $post->ID); ?>

Getting Unix Timestamp

Assigns the local time of the current post in seconds (since January 1 1970, known as the Unix Epoch) to the variable $u_time.

<?php $local_timestamp = get_the_time('U'); ?>

In most cases, you would probably want the epoch time for GMT (rather than for the local time zone), which you can get with the get_post_time() function, setting the $gmt option to true:

<?php $gmt_timestamp = get_post_time('U', true); ?>


Source File

get_the_time() is located in wp-includes/general-template.php


get_calendar(), get_day_link(), get_month_link(), get_the_date(), get_the_time(), get_year_link(), single_month_title(), the_date(), the_date_xml(), the_modified_date(), get_the_modified_date(), the_modified_time(), get_the_modified_time(), the_time()

See also index of Function Reference and index of Template Tags.