get_gmt_from_date()
get_gmt_from_date( string $string, string $format = ‘Y-…
get_gmt_from_date( string $string, string $format = ‘Y-m-d H:i:s’ )
给定站点时区中的日期,以UTC时区返回该日期。
Given a date in the timezone of the site, returns that date in UTC timezone.
目录锚点:#说明#参数#返回#源码#笔记
说明(Description)
需要并返回Y-m-d H:i:s格式的日期。可以使用$format参数重写返回格式。
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $string | (string) | 必需 | 要转换的日期,在站点的时区中。 |
| $format | (string) | 可选 | 返回日期的格式字符串。 |
返回(Return)
(string)日期的格式化版本,以UTC时区为单位。
源码(Source)
/**
* Returns a date in the GMT equivalent.
*
* Requires and returns a date in the Y-m-d H:i:s format. If there is a
* timezone_string available, the date is assumed to be in that timezone,
* otherwise it simply subtracts the value of the 'gmt_offset' option. Return
* format can be overridden using the $format parameter.
*
* @since 1.2.0
*
* @param string $string The date to be converted.
* @param string $format The format string for the returned date (default is Y-m-d H:i:s)
* @return string GMT version of the date provided.
*/
function get_gmt_from_date( $string, $format = 'Y-m-d H:i:s' ) {
$tz = get_option( 'timezone_string' );
if ( $tz ) {
$datetime = date_create( $string, new DateTimeZone( $tz ) );
if ( ! $datetime )
return gmdate( $format, 0 );
$datetime->setTimezone( new DateTimeZone( 'UTC' ) );
$string_gmt = $datetime->format( $format );
} else {
if ( ! preg_match( '#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches ) )
return gmdate( $format, 0 );
$string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] );
$string_gmt = gmdate( $format, $string_time - get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
}
return $string_gmt;
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 1.2.0 | wp-includes/formatting.php:3513 | 9 | 1 function |
笔记(Notes)
与此相反的是从格林尼治时间获取日期
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。





还没有任何评论,赶紧来占个楼吧!