Switch language
wpseek on Twitter


A WordPress-centric search engine for devs and theme authors




current_time [ ]

current_time ( $type, $gmt = 0 )
Parameters:
  • (string) $type Either 'mysql' or 'timestamp'.
  • (int|bool) $gmt Optional. Whether to use GMT timezone. Default is false.
Returns:
  • (int|string) String if $type is 'gmt', int if $type is 'timestamp'.
Defined at:
Codex



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.

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.

Source

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 ) ) );
			break;
		case 'timestamp':
			return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
			break;
	}
}

Examples [ wp-snippets.com ]

Top Google Search Results

More ...

0 User Note(s)

None yet. Be the first!

Add New ...