WordPress.org

Ready to get started?Download WordPress

Codex

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

Template Tags/get post 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 can be used within The Loop.

Usage

 <?php get_post_time$d$gmt$post$translate ); ?> 

Parameters

d
(string) (optional) The format used to display the time (and date). See Formatting Date and Time for other time and date formats.
Default: 'U' (unix timestamp)
gmt
(bool) (optional) Set true to return time in GMT time zone.
Default: false
post
(integer/object) (optional) post ID or object.
Default: null. global $post object
translate
(bool) (optional) Whether to translate the time string
Default: false

Usage

This function is used internally by other functions, such as get_the_time().

Getting Unix Timestamp

The proper way to get the GMT timestamp for a post is by setting the $gmt option to true:

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

Changelog

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.