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
参数
- $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
你可能对这些文章感兴趣:
- wordpress函数get_the_posts_navigation()用法示例
- wordpress函数get_the_title()用法示例
- wordpress函数get_the_terms()用法示例
- wordpress函数get_the_tags()用法示例
- wordpress函数get_the_taxonomies()用法示例
- wordpress函数get_the_permalink()用法示例
- wordpress函数get_the_password_form()用法示例
- wordpress函数get_the_posts_pagination()用法示例
- wordpress函数get_the_modified_time()用法示例
- wordpress函数get_the_modified_date()用法示例
- wordpress函数get_the_modified_author()用法示例
- wordpress函数get_the_guid()用法示例
- wordpress函数get_the_ID()用法示例
- wordpress函数get_the_excerpt()用法示例
如有疑问,请前往问答中心反馈!
反馈