Retrieves the current time based on specified type.
$gmt.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.
$typestringrequired
'mysql', 'timestamp', 'U', or PHP date format string (e.g. 'Y-m-d').$gmtint|booloptional
$type is 'timestamp' or 'U', string otherwise.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) ( (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 );
}
© 2003–2024 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/current_time