^ 回到顶部
  • 人生没有定律,每个人都有自己的节奏
  • 本站wordpress建站教程均通过实践后发布,希望对你有帮助
  • 希望你的坚持,都是因为热爱,而不是因为不甘心
  • 8年wordpress建站经验,5星服务品质
  • 那些不愿意让你吃亏的人,才是真正值得你深交的人,也是值得你付出时间的人
  • 阿里云2核2g仅需86元/年

wordpress函数get_gmt_from_date()用法示例

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.

新用户2核2g仅需86元/年    领取1153套模板    免费cdn流量包    ¥3188礼包


参数

$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


让小雨知道,这篇文章帮到了你
扫码关注微信公众号zs40086(微搜片)随时随地微信看片,抢先福利电影等你来

热门推荐

如有疑问,请前往问答中心反馈!

反馈