函数原型
current_time( string $type, int|bool $gmt ): int|string
函数描述
Retrieves the current time based on specified type.
是否弃用
未弃用
函数参数
-
$type
string
Required - Type of time to retrieve. Accepts
'mysql','timestamp','U', or PHP date format string (e.g.'Y-m-d'). -
$gmt
int|bool
Optional - Whether to use GMT timezone. Default false.
函数返回值
int|string Integer if $type is 'timestamp' or 'U', string otherwise.
函数位置
File: wp-includes/functions.php.
函数源码
function current_time( $type, $gmt = 0 ) {
// 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) ( 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 );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 5.3.0 | Now returns an integer if $type is 'U'. Previously a string was returned. |
| 1.0.0 | Introduced. |

