wpseek.com
WordPress开发者和主题制作者的搜索引擎
current_time › WordPress Function
Since1.0.0
已弃用n/a
› current_time ( $type, $gmt = false )
| 参数: (2) |
|
| 返回: |
|
| 定义在: |
|
| 文档: | |
| Change Log: |
|
Retrieves the current time based on specified type.
- The 'mysql' type will return the time in the format for MySQL DATETIME field. - The 'timestamp' or 'U' types will return the current timestamp or a sum of timestamp and timezone offset, depending on$gmt.
- Other strings will be interpreted as PHP date formats (e.g. 'Y-m-d').
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.Related Functions: current_datetime, current_action, current_filter, get_current_theme, comment_time
源码
function current_time( $type, $gmt = false ) {
// 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 );
}