WordPress at a glance

current_time() WP 1.0

Retrieve the current time based on specified type.

The 'mysql' type will return the time in the format for MySQL DATETIME field. The 'timestamp' type 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 set to either '1' or 'true', then both types will use GMT time. if $gmt is false, the output is adjusted with the GMT offset in the WordPress option.


Int/String. Integer if $type is 'timestamp', string otherwise.

1 time = 0.000011s = very fast | 50000 times = 0.03s = speed of light | PHP 7.1.2, WP 4.7.3

No Hooks.


current_time( $type, $gmt );
$type(string) (required)
Type of time to retrieve. Accepts 'mysql', 'timestamp', or PHP date format string (e.g. 'Y-m-d').
Whether to use GMT timezone.
Default: false

Список изменений

С версии 1.0.0 Введена.

Code of current_time() WP 5.5.1

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

Related Functions

From tag: date time

No comments
    Log In . Register