get_post_time()
Gets the time of the current post creation in the specified format. You can specify a return format (the default is Unix format). Must be used in WordPress loop.
The function gets a result for processing in php, and does not display it to the screen. Use the_time() to display the result.
Uses: mysql2date()
Used By: get_the_time()
Hooks from the function
Return
String|Int|false
. Formatted date string or Unix timestamp if $format is 'U' or 'G'. False on failure.
Usage
get_post_time( $format, $gmt, $post, $translate );
- $format(string)
- Format to use for retrieving the time the post was written. Accepts 'G', 'U', or PHP date format.
Default: 'U' - $gmt(true|false)
- Whether to retrieve the GMT time.
Default: false - $post(int|WP_Post)
- Post ID or post object.
Default: global $post object - $translate(true|false)
- Whether to translate the 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. |