WordPress.org

Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/get the time

Description

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.

Usage

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

Parameters

format
(string) (optional) The format used to display the time (and date). See Formatting Date and Time for other time and date formats. WordPress is written in the programming language PHP. The date formatting functions in WordPress use PHP's built-in date formatting functions.
Default: Time Format configured in Administration > Settings > General
post
(integer/object) (optional) post ID or object.
Default: null. global $post object

Return Values

(string) 
Returns the time according to the default or specified time format.

Examples

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 $local_timestamp .

<?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); ?>

Changelog

Source File

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

Related

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.