On this page
get_gmt_from_date( string $string, string $format = 'Y-m-d H:i:s' ): string
Given a date in the timezone of the site, returns that date in UTC.
Description
Requires and returns a date in the Y-m-d H:i:s format.
Return format can be overridden using the $format parameter.
Parameters
$stringstring Required-
The date to be converted, in the timezone of the site.
$formatstring Optional-
The format string for the returned date.
Default:
'Y-m-d H:i:s'
Return
string Formatted version of the date, in UTC.
Source
File: wp-includes/formatting.php. View all references
function get_gmt_from_date( $string, $format = 'Y-m-d H:i:s' ) {
$datetime = date_create( $string, wp_timezone() );
if ( false === $datetime ) {
return gmdate( $format, 0 );
}
return $datetime->setTimezone( new DateTimeZone( 'UTC' ) )->format( $format );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_timezone() wp-includes/functions.php | Retrieves the timezone of the site as a |
Used By
| Used By | Description |
|---|---|
| WP_REST_Posts_Controller::prepare_item_for_response() wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php | Prepares a single post output for response. |
| rest_get_date_with_gmt() wp-includes/rest-api.php | Parses a date into both its local and UTC equivalent, in MySQL datetime format. |
| _wp_translate_postdata() wp-admin/includes/post.php | Renames |
| WP_Customize_Manager::save() wp-includes/class-wp-customize-manager.php | Handles customize_save WP Ajax request to save/update a changeset. |
| _future_post_hook() wp-includes/post.php | Hook used to schedule publication for a post marked for the future. |
| wp_insert_post() wp-includes/post.php | Inserts or update a post. |
| wp_xmlrpc_server::_convert_date_gmt() wp-includes/class-wp-xmlrpc-server.php | Convert a WordPress GMT date string to an IXR_Date object. |
| wp_update_comment() wp-includes/comment.php | Updates an existing comment in the database. |
| wp_insert_comment() wp-includes/comment.php | Inserts a comment into the database. |
Changelog
| Version | Description |
|---|---|
| 1.2.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/get_gmt_from_date