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

wordpress函数get_date_from_gmt()用法示例

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

Converts a GMT date into the correct format for the blog.


描述

Requires and returns a date in the Y-m-d H:i:s format. If there is a timezone_string available, the returned date is in that timezone, otherwise it simply adds the value of gmt_offset. 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) Formatted date relative to the timezone / GMT offset.


源代码

File: wp-includes/formatting.php

function get_date_from_gmt( $string, $format = 'Y-m-d H:i:s' ) {
	$tz = get_option( 'timezone_string' );
	if ( $tz ) {
		$datetime = date_create( $string, new DateTimeZone( 'UTC' ) );
		if ( ! $datetime )
			return date( $format, 0 );
		$datetime->setTimezone( new DateTimeZone( $tz ) );
		$string_localtime = $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 date( $format, 0 );
		$string_time = gmmktime( $matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1] );
		$string_localtime = gmdate( $format, $string_time + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
	}
	return $string_localtime;
}

更新日志

Version 描述
1.2.0 Introduced.

相关函数

Uses

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

Used By

  • wp-includes/class-wp-customize-manager.php:
    WP_Customize_Manager::save_changeset_post()
  • wp-includes/rest-api.php:
    rest_get_date_with_gmt()
  • wp-includes/post.php:
    wp_insert_post()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::mw_editPost()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::mw_newPost()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::wp_editComment()
  • wp-includes/class-wp-xmlrpc-server.php:
    wp_xmlrpc_server::_insert_post()
  • Show 2 more used by
    Hide more used by


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

热门推荐

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

反馈