get_post_time()
Gets the publication time of the post in the specified format (default is unix timestamp). Used inside the WordPress loop.
The function gets the result for processing, not outputting it to the screen. To output, use the function the_time().
Also read: Date/Time in WordPress.
Uses: mysql2date()
Used By: get_the_time()
Hooks from the function
Returns
String|Int|false. A string of time in the specified format.
Usage
get_post_time( $d, $gmt, $post, $translate );
- $d(string)
- Date format. For example, j F Y will output "12 December 2010". Possible formats..
Default: 'U' (Unix timestamp) - $gmt(boolean)
- Set to true to get the post time in GMT zone ($post->post_date_gmt).
Default: false - $post(int/WP_Post)
- ID of the post whose time you want to get. You can pass a post object.
Default: null. object $post - $translate(boolean)
- Is it necessary to translate the obtained time string?
Default: false
Examples
#1 Get the timestamp of the post
To get a Unix timestamp of a post adjusted for the GMT time zone (the second parameter), you can use the function like so:
$gmt_timestamp = get_post_time( 'U', true ); echo $gmt_timestamp; //> 1521992006
Changelog
| Since 2.0.0 | Introduced. |