WordPress函数文档do_feed_atom()
获取当前时间并格式化 描述 译文 函数current_time(“mysql”, $gmt)返回格式为“年-月…
获取当前时间并格式化
描述
译文
函数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”参数值几乎没有任何用处。
原文
Returns the blog’s current local time in the specified format. There are two named formats: ‘mysql’ for MySQL’s timestamp data type format (i.e. YYYY-MM-DD HH:MM:SS), and ‘timestamp’ for the Unix timestamp format (i.e. epoch). Other strings will be interpreted as PHP date formats (e.g. ‘Y-m-d’) since 3.9.0. The optional secondary parameter can be used to retrieve GMT time instead of the blog’s local time.
The local time returned is based on the timezone set on the blog’s General Settings page, which is UTC by default.
current_time( ‘timestamp’ ) should be used in lieu of time() to return the blog’s local time. In WordPress, PHP’s time() will always return UTC and is the same as calling current_time( ‘timestamp’, true ).
用法
<?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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
/* ———————————-
* wordpress函数 kim收集
* ———————————- */
/**
* 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()
- 原文:http://codex.wordpress.org/Function_Reference/current_time
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。
评论功能已经关闭!