get_gmt_from_date() - WordPress 函数参考中文文档

返回介绍

get_gmt_from_date()

发布于 2017-09-10 字数3063 浏览 614 评论 0

get_gmt_from_date( string $string,  string $format = 'Y-m-d H:i:s' )

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.


参数

$string

(string)
(Required)
The date to be converted.

$format

(string)
(Optional)
The format string for the returned date (default is Y-m-d H:i:s)

Default value: ‘Y-m-d H:i:s’


返回值

(string) GMT version of the date provided.


源代码

File: wp-includes/formatting.php

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 ) ) {
			$datetime = strtotime( $string );
			if ( false === $datetime ) {
				return gmdate( $format, 0 );
			}
			return gmdate( $format, $datetime );
		}
		$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;
}

更新日志

Version 描述
1.2.0 Introduced.

相关函数

Uses

  • wp-includes/option.php:
    get_option()

Used By

  • wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php:
    WP_REST_Posts_Controller::prepare_item_for_response()
  • wp-includes/rest-api.php:
    rest_get_date_with_gmt()
  • wp-admin/includes/post.php:
    _wp_translate_postdata()
  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::save()
  • wp-includes/post.php:
    _future_post_hook()
  • wp-includes/post.php:
    wp_insert_post()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::_convert_date_gmt()
  • wp-includes/comment.php:
    wp_update_comment()
  • wp-includes/comment.php:
    wp_insert_comment()
  • Show 4 more used by
    Hide more used by


User Contributed Notes

上一篇:get_front_page_template()

下一篇:get_header()

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

目前还没有任何评论,快来抢沙发吧!