current_time( string $type, int|bool $gmt )
Retrieves the current time based on specified type.
Description
- 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’).
- The ‘timestamp’ or ‘U’ types will return the current timestamp or a sum of timestamp and timezone offset, depending on
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.
Parameters
- $type
-
(Required) Type of time to retrieve. Accepts 'mysql', 'timestamp', 'U', or PHP date format string (e.g. 'Y-m-d').
- $gmt
-
(Optional) Whether to use GMT timezone. Default false.
Return
(int|string) Integer if $type
is 'timestamp' or 'U', string otherwise.
Source
File: wp-includes/functions.php
function current_time( $type, $gmt = 0 ) {
switch ( $type ) {
case 'mysql':
return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) ) );
case 'timestamp':
return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
default:
return ( $gmt ) ? date( $type ) : date( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
}
}
Changelog
Version | Description |
---|---|
5.3.0 | Now returns an integer if $type is 'U'. Previously a string was returned. |
1.0.0 | Introduced. |