current_time()
Проверено на WordPress 6.9, обновлено Источник: WordPress Developer Resources.
Сигнатура
current_time( string $type, bool $gmt = false ): int|string
Описание
Тип «mysql» возвращает время в формате поля MySQL DATETIME.
Типы «timestamp» или «U» возвращают текущую метку времени или сумму метки времени и смещения часового пояса, в зависимости от $gmt.
Прочие строки интерпретируются как форматы даты PHP (например, «Y-m-d»).
Если $gmt имеет истинное значение, то оба типа используют время GMT, иначе вывод корректируется на смещение GMT для сайта.
Оригинал (английский)
- The ‘mysql’ type will return the time in the format for MySQL DATETIME field.
- The ‘timestamp’ or ‘U’ types will return the current timestamp or a sum of timestamp and timezone offset, depending on
$gmt. - Other strings will be interpreted as PHP date formats (e.g. ‘Y-m-d’).
If $gmt is a truthy value then both types will use GMT time, otherwise the output is adjusted with the GMT offset for the site.
Параметры
$type
string
обязательный
$gmt
bool
необязательный
= false
Возвращаемое значение
int|string
Исходный код
wp-includes/functions.php:78
function current_time( $type, $gmt = false ) {
// Don't use non-GMT timestamp, unless you know the difference and really need to.
if ( 'timestamp' === $type || 'U' === $type ) {
return $gmt ? time() : time() + (int) ( (float) get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
}
if ( 'mysql' === $type ) {
$type = 'Y-m-d H:i:s';
}
$timezone = $gmt ? new DateTimeZone( 'UTC' ) : wp_timezone();
$datetime = new DateTime( 'now', $timezone );
return $datetime->format( $type );
}
История изменений
| Версия | Описание |
|---|---|
| 5.3.0 | Now returns an integer if $type is 'U'. Previously a string was returned. |
| 1.0.0 | Introduced. |

