Title: get_post_time
Published: April 25, 2014
Last modified: August 20, 2026

---

# get_post_time( string $format = 'U', bool $gmt = false, int|WP_Post|null $post = null, bool $translate = false ): string|int|false

## In this article

 * [Parameters](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#changelog)
 * [User Contributed Notes](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#user-contributed-notes)

[ Back to top](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#wp--skip-link--target)

Retrieves the localized time of the post.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#parameters)󠁿

 `$format`stringoptional

Format to use for retrieving the time the post was written. Accepts `'G'`, `'U'`,
or PHP date format. Default `'U'`.

Default:`'U'`

`$gmt`booloptional

Whether to retrieve the GMT time.

Default:`false`

`$post`int|[WP_Post](https://developer.wordpress.org/reference/classes/wp_post/)
|nulloptional

Post ID or post object. Default is global `$post` object.

Default:`null`

`$translate`booloptional

Whether to translate the time string.

Default:`false`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#return)󠁿

 string|int|false Formatted date string or Unix timestamp if `$format` is `'U'` 
or `'G'`.
 False on failure.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#source)󠁿

    ```php
    function get_post_time( $format = 'U', $gmt = false, $post = null, $translate = false ) {
    	$post = get_post( $post );

    	if ( ! $post ) {
    		return false;
    	}

    	$source   = ( $gmt ) ? 'gmt' : 'local';
    	$datetime = get_post_datetime( $post, 'date', $source );

    	if ( false === $datetime ) {
    		return false;
    	}

    	if ( 'U' === $format || 'G' === $format ) {
    		$time = $datetime->getTimestamp();

    		// Returns a sum of timestamp with timezone offset. Ideally should never be used.
    		if ( ! $gmt ) {
    			$time += $datetime->getOffset();
    		}
    	} elseif ( $translate ) {
    		$time = wp_date( $format, $datetime->getTimestamp(), $gmt ? new DateTimeZone( 'UTC' ) : null );
    	} else {
    		if ( $gmt ) {
    			$datetime = $datetime->setTimezone( new DateTimeZone( 'UTC' ) );
    		}

    		$time = $datetime->format( $format );
    	}

    	/**
    	 * Filters the localized time of the post.
    	 *
    	 * @since 2.6.0
    	 *
    	 * @param string|int $time   Formatted date string or Unix timestamp if `$format` is 'U' or 'G'.
    	 * @param string     $format Format to use for retrieving the date of the post.
    	 *                           Accepts 'G', 'U', or PHP date format.
    	 * @param bool       $gmt    Whether to retrieve the GMT time.
    	 */
    	return apply_filters( 'get_post_time', $time, $format, $gmt );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/general-template.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/7.1/src/wp-includes/general-template.php#L3094)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/7.1/src/wp-includes/general-template.php#L3094-L3136)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#hooks)󠁿

 [apply_filters( ‘get_post_time’, string|int $time, string $format, bool $gmt )](https://developer.wordpress.org/reference/hooks/get_post_time/)

Filters the localized time of the post.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_date()](https://developer.wordpress.org/reference/functions/wp_date/)`wp-includes/functions.php` |

Retrieves the date, in localized format.

  | 
| [get_post_datetime()](https://developer.wordpress.org/reference/functions/get_post_datetime/)`wp-includes/general-template.php` |

Retrieves post published or modified time as a `DateTimeImmutable` object instance.

  | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_post()](https://developer.wordpress.org/reference/functions/get_post/)`wp-includes/post.php` |

Retrieves post data given a post ID or post object.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#)

| Used by | Description | 
| [export_wp()](https://developer.wordpress.org/reference/functions/export_wp/)`wp-admin/includes/export.php` |

Generates the WXR export file for download.

  | 
| [get_the_time()](https://developer.wordpress.org/reference/functions/get_the_time/)`wp-includes/general-template.php` |

Retrieves the time of the post.

  | 
| [the_weekday()](https://developer.wordpress.org/reference/functions/the_weekday/)`wp-includes/general-template.php` |

Displays the localized weekday for the post.

  | 
| [the_weekday_date()](https://developer.wordpress.org/reference/functions/the_weekday_date/)`wp-includes/general-template.php` |

Displays the localized weekday for the post.

  | 
| [get_the_date()](https://developer.wordpress.org/reference/functions/get_the_date/)`wp-includes/general-template.php` |

Retrieves the date of the post.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.0.0](https://developer.wordpress.org/reference/since/2.0.0/) | Introduced. |

## 󠀁[User Contributed Notes](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#user-contributed-notes)󠁿

 1.  [Skip to note 2 content](https://developer.wordpress.org/reference/functions/get_post_time/?output_format=md#comment-content-6836)
 2.   [Gwyneth Llewelyn](https://profiles.wordpress.org/gwynethllewelyn/)  [  3 years ago  ](https://developer.wordpress.org/reference/functions/get_post_time/#comment-6836)
 3. [You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_time%2F%23comment-6836)
    Vote results for this note: 0[You must log in to vote on the helpfulness of this note](https://login.wordpress.org?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_time%2F%23comment-6836)
 4. For a complete list of date/time formatting options, the ‘PHP date format’ is available
    from the [PHP.net reference website](https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#datetimeimmutable.createfromformat.parameters).
 5.  [Log in to add feedback](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_time%2F%3Freplytocom%3D6836%23feedback-editor-6836)

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fget_post_time%2F)
before being able to contribute a note or feedback.