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. 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.

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

No Hooks.

Return

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

Usage

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').
$gmt(int/true/false)
Whether to use GMT timezone.
Default: false

Code of current_time: wp-includes/functions.php VER 5.0.1

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

Related Functions

From tag: date time

No comments
    Hello, !     Log In . Register