On this page
current_time( string $type, int|bool $gmt ): int|string
Retrieves the current time based on specified type.
Description
- The ‘mysql’ type will return the time in the format for MySQL DATETIME field.
- The ‘timestamp’ or ‘U’ types will return the current timestamp or a sum of timestamp and timezone offset, depending on
$gmt. - Other strings will be interpreted as PHP date formats (e.g. ‘Y-m-d’).
- The ‘timestamp’ or ‘U’ types will return the current timestamp or a sum of timestamp and timezone offset, depending on
If $gmt is a truthy value then both types will use GMT time, otherwise the output is adjusted with the GMT offset for the site.
Parameters
$typestring Required-
Type of time to retrieve. Accepts
'mysql','timestamp','U', or PHP date format string (e.g.'Y-m-d'). $gmtint|bool Optional-
Whether to use GMT timezone. Default false.
Return
int|string Integer if $type is 'timestamp' or 'U', string otherwise.
Source
File: wp-includes/functions.php. View all references
function current_time( $type, $gmt = 0 ) {
// Don't use non-GMT timestamp, unless you know the difference and really need to.
if ( 'timestamp' === $type || 'U' === $type ) {
return $gmt ? time() : time() + (int) ( get_option( 'gmt_offset' ) * HOUR_IN_SECONDS );
}
if ( 'mysql' === $type ) {
$type = 'Y-m-d H:i:s';
}
$timezone = $gmt ? new DateTimeZone( 'UTC' ) : wp_timezone();
$datetime = new DateTime( 'now', $timezone );
return $datetime->format( $type );
}
Related
Uses
| Uses | Description |
|---|---|
| wp_timezone() wp-includes/functions.php | Retrieves the timezone of the site as a |
| get_option() wp-includes/option.php | Retrieves an option value based on an option name. |
Used By
| Used By | Description |
|---|---|
| wp_resolve_post_date() wp-includes/post.php | Uses wp_checkdate to return a valid Gregorian-calendar value for post_date. |
| wp_insert_site() wp-includes/ms-site.php | Inserts a new site into the database. |
| wp_update_site() wp-includes/ms-site.php | Updates a site in the database. |
| wp_create_user_request() wp-includes/user.php | Creates and logs a user request to perform a specific action. |
| wp_privacy_generate_personal_data_export_file() wp-admin/includes/privacy-tools.php | Generate the personal data export file. |
| WP_Customize_Manager::save_changeset_post() wp-includes/class-wp-customize-manager.php | Saves the post for the loaded changeset. |
| WP_REST_Comments_Controller::create_item() wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php | Creates a comment. |
| _wp_upload_dir() wp-includes/functions.php | A non-filtered, non-cached version of wp_upload_dir() that doesn’t check the path. |
| WP_Customize_Manager::customize_pane_settings() wp-includes/class-wp-customize-manager.php | Prints JavaScript settings for parent window. |
| populate_network() wp-admin/includes/schema.php | Populate network settings. |
| wp_dashboard_recent_posts() wp-admin/includes/dashboard.php | Generates Publishing Soon and Recently Published sections. |
| wp_install_defaults() wp-admin/includes/upgrade.php | Creates the initial content for a newly-installed site. |
| touch_time() wp-admin/includes/template.php | Prints out HTML form date elements for editing post or comment publish date. |
| media_handle_upload() wp-admin/includes/media.php | Saves a file submitted from a POST request and create an attachment post for it. |
| media_handle_sideload() wp-admin/includes/media.php | Handles a side-loaded file in the same way as an uploaded file is handled by media_handle_upload() . |
| post_submit_meta_box() wp-admin/includes/meta-boxes.php | Displays post submit form fields. |
| get_calendar() wp-includes/general-template.php | Displays calendar with days that have posts as links. |
| WP_Query::get_posts() wp-includes/class-wp-query.php | Retrieves an array of posts based on query variables. |
| date_i18n() wp-includes/functions.php | Retrieves the date in localized format, based on a sum of Unix timestamp and timezone offset in seconds. |
| get_month_link() wp-includes/link-template.php | Retrieves the permalink for the month archives with year. |
| get_day_link() wp-includes/link-template.php | Retrieves the permalink for the day archives with year and month. |
| get_year_link() wp-includes/link-template.php | Retrieves the permalink for the year archives. |
| WP_Date_Query::build_mysql_datetime() wp-includes/class-wp-date-query.php | Builds a MySQL format date/time based on some query parameters. |
| wp_insert_post() wp-includes/post.php | Inserts or update a post. |
| wp_update_post() wp-includes/post.php | Updates a post with new post data. |
| wpmu_log_new_registrations() wp-includes/ms-functions.php | Logs the user email, IP, and registration date of a new site. |
| wpmu_activate_signup() wp-includes/ms-functions.php | Activates a signup. |
| wpmu_signup_blog() wp-includes/ms-functions.php | Records site signup information for future activation. |
| wpmu_signup_user() wp-includes/ms-functions.php | Records user signup information for future activation. |
| wpmu_update_blogs_date() wp-includes/ms-blogs.php | Update the last_updated field for the current site. |
| wp_xmlrpc_server::blogger_newPost() wp-includes/class-wp-xmlrpc-server.php | Creates new post. |
| wp_new_comment() wp-includes/comment.php | Adds a new comment to the database. |
| wp_insert_comment() wp-includes/comment.php | Inserts a comment into the database. |
Changelog
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/current_time