The get_the_time() WordPress PHP function retrieves the time at which the post was written.
Usage
echo get_the_time( $format, $post ); // your custom code here
Parameters
$format
string (Optional): Format to use for retrieving the time the post was written. Accepts ‘G’, ‘U’, or PHP date format. Defaults to the ‘time_format’ option. Default:''
$post
int|WP_Post (Optional): Post ID or post object. Default is global$post
object. Default:null
More information
See WordPress Developer Resources: get_the_time()
Examples
Display post time in the default format
This example displays the post time using the default ‘time_format’ option.
echo get_the_time(); // your custom code here
Display post time in a custom format
This example displays the post time in a custom format, such as ‘H:i:s’.
echo get_the_time('H:i:s'); // your custom code here
Display post time in a Unix timestamp
This example displays the post time as a Unix timestamp by using ‘U’ as the format.
echo get_the_time('U'); // your custom code here
Display post time for a specific post ID
This example displays the post time for a specific post ID (e.g., 42) using the default ‘time_format’ option.
echo get_the_time('', 42); // your custom code here
Display post time using a custom format and specific post object
This example displays the post time using a custom format (e.g., ‘H:i:s’) and a specific post object.
$post_object = get_post(42); echo get_the_time('H:i:s', $post_object); // your custom code here