do_feed_atom()

获取当前时间并格式化

描述

函数current_time(“mysql”, $gmt)返回格式为“年-月-日 时:分:秒”的时间。如果$gmt=1,返回的时间为GMT时间;如果$gmt=0,返回的时间为浏览器客户端本地时间(由WordPress选项gmt_offset决定,在“常规”菜单下的“时区”选项中进行设置)。

警告: current_time(‘timestamp’,1)返回(作为时间标记)服务器时间,而不是GMT时间!PHP函数time()返回的才是GMT时间,使用time()时不必再使用current_time(‘timestamp’,1)。

警告: current_time(‘timestamp’,0) 返回GMT + gmt_offset(服务器) + gmt_offset(浏览器)的时间标记——这是一个无意义的组合。

“timestamp”参数值几乎没有任何用处。

用法

<?php $time = current_time( $type, $gmt = 0 ); ?>

参数

$type

(string) (必填) The time format to return. Possible values:

mysql
timestamp
A PHP date format (e.g. ‘Y-m-d’) (since 3.9)

默认值: None

$gmt

(integer) (可选) The time zone (GMT, local) of the returned time: Possible values:

1
0

默认值: 0

历史

添加于 版本: 1.0

3.9.0: $type can now be any PHP date format.

源文件

current_time() 函数的代码位于 wp-includes/functions.php

/**
* 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.
*
* @since 1.0.0
*
* @param string   $type Type of time to retrieve. Accepts ‘mysql’, ‘timestamp’, or PHP date
*                       format string (e.g. ‘Y-m-d’).
* @param int|bool $gmt  Optional. Whether to use GMT timezone. Default false.
* @return int|string Integer if $type is ‘timestamp’, string otherwise.
*/

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

}

}

相关

Time Function(函数)s: current_time(), human_time_diff(), the_time(), get_the_time(), comment_time()

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索