WordPress开发者和主题制作者的搜索引擎



current_time ›

Since1.0.0
已弃用n/a
current_time ( $type, $gmt = 0 )
参数: (2)
  • (string) $type Type of time to retrieve. Accepts 'mysql', 'timestamp', or PHP date format string (e.g. 'Y-m-d').
    Required: Yes
  • (int|bool) $gmt Optional. Whether to use GMT timezone. Default false.
    Required: No
    默认:
返回:
  • (int|string) Integer if $type is 'timestamp', string otherwise.
定义在:
文档:

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.



源码

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 ) ? gmdate( $type ) : gmdate( $type, time() + ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS ) );
	}
}