current_time()
最后更新于:2021-11-25 22:41:15
current_time( string$type, int|bool$gmt)Retrieves the current time based on specified type.
参数
- $type
-
(string) (Required) Type of time to retrieve. Accepts ‘mysql’, ‘timestamp’, or PHP date format string (e.g. ‘Y-m-d’).
- $gmt
-
(int|bool) (Optional) Whether to use GMT timezone. Default false.
响应
(int|string) Integer if $type is ‘timestamp’, string otherwise.
源文件
文件: gc-includes/functions.php
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) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
}
if ( 'mysql' === $type ) {
$type = 'Y-m-d H:i:s';
}
$timezone = $gmt ? new DateTimeZone( 'UTC' ) : gc_timezone();
$datetime = new DateTime( 'now', $timezone );
return $datetime->format( $type );
}