# get_post_time()

URL: https://chugunov.pro/api-wordpress/functions/get_post_time/
Проверено на WordPress 6.9, обновлено 06.08.2026.
Источник: независимый русскоязычный справочник chugunov.pro. Не является официальной документацией WordPress.

Тип: функция.
Появился в версии: 2.0.0.

## Сигнатура

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

## Описание

Извлекает локализованное время записи.

## Параметры

- `$format` `string` — необязательный, по умолчанию `'U'`. Формат для получения времени написания записи. Принимает 'G', 'U' или формат даты PHP. Значение по умолчанию 'U'.
- `$gmt` `bool` — необязательный, по умолчанию `false`. Получать ли время по GMT.
- `$post` `int|WP_Post|null` — необязательный, по умолчанию `null`. ID записи или объект записи. По умолчанию — глобальный объект $post .
- `$translate` `bool` — необязательный, по умолчанию `false`. Переводить ли строку времени.

## Возвращаемое значение

`string|int|false` — $format 'U' 'G'

## Исходный код

Файл: `wp-includes/general-template.php:2889`

```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 );
}
```

## История изменений

- 2.0.0 — Introduced.

## Связанные

Использует: [`wp_date`](https://chugunov.pro/api-wordpress/functions/wp_date/), [`get_post_datetime`](https://chugunov.pro/api-wordpress/functions/get_post_datetime/), [`apply_filters`](https://chugunov.pro/api-wordpress/functions/apply_filters/), [`get_post`](https://chugunov.pro/api-wordpress/functions/get_post/).
Используется в: [`export_wp`](https://chugunov.pro/api-wordpress/functions/export_wp/), [`get_the_time`](https://chugunov.pro/api-wordpress/functions/get_the_time/), [`the_weekday`](https://chugunov.pro/api-wordpress/functions/the_weekday/), [`the_weekday_date`](https://chugunov.pro/api-wordpress/functions/the_weekday_date/), [`get_the_date`](https://chugunov.pro/api-wordpress/functions/get_the_date/).

Оригинал в официальной документации: https://developer.wordpress.org/reference/functions/get_post_time/
