Bạn đang xem: Php time() function : how to get current timestamp? formatting the current date and time in php
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.
Top ↑
(string)(Required)Type of time lớn retrieve. Accepts "mysql", "timestamp", "U", or PHP date format string (e.g. "Y-m-d").
$gmt(int|bool)(Optional) Whether to lớn use GMT timezone. Mặc định false.
Top ↑
(int|string) Integer if $type is "timestamp" or "U", string otherwise.
Top ↑
File: wp-includes/functions.php
function current_time( $type, $gmt = 0 ) // Don"t use non-GMT timestamp, unless you know the difference & really need to.if ( "timestamp" === $type
Expand full source codeCollapse full source codeView on TracView on GitHub
Top ↑
Top ↑
wp-includes/functions.php:wp_timezone() | Retrieves the timezone of the site as a DateTimeZone object. |
wp-includes/option.php:get_option() | Retrieves an option value based on an option name. |
Top ↑
wp-includes/post.php:wp_resolve_post_date() | Uses wp_checkdate khổng lồ return a valid Gregorian-calendar value for post_date. |
wp-includes/ms-site.php:wp_insert_site() | Inserts a new site into the database. |
wp-includes/ms-site.php:wp_update_site() | Updates a site in the database. |
wp-includes/user.php:wp_create_user_request() | Create & log a user request khổng lồ perform a specific action. |
wp-admin/includes/privacy-tools.php:wp_privacy_generate_personal_data_export_file() | Generate the personal data export file. |
wp-includes/class-wp-customize-manager.php:WP_Customize_Manager::save_changeset_post() | Save the post for the loaded changeset. |
wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php:WP_REST_Comments_Controller::create_item() | Creates a comment. |
wp-includes/functions.php:_wp_upload_dir() | A non-filtered, non-cached version of wp_upload_dir() that doesn’t check the path. |
wp-includes/class-wp-customize-manager.php:WP_Customize_Manager::customize_pane_settings() | Print JavaScript settings for parent window. |
wp-admin/includes/schema.php:populate_network() | Populate network settings. |
wp-admin/includes/dashboard.php:wp_dashboard_recent_posts() | Generates Publishing Soon and Recently Published sections. |
wp-admin/includes/upgrade.php:wp_install_defaults() | Creates the initial nội dung for a newly-installed site. |
wp-admin/includes/template.php:touch_time() | Print out HTML khung date elements for editing post or bình luận publish date. |
wp-admin/includes/media.php:media_handle_upload() | Saves a file submitted from a POST request và create an attachment post for it. |
wp-admin/includes/media.php:media_handle_sideload() | Handles a side-loaded tệp tin in the same way as an uploaded tệp tin is handled by media_handle_upload(). Xem thêm: Broadcast Ssid Là Gì ? Tìm Hiểu Tổng Quan Về Ssid? Tất Tần Tật Mọi Thông Tin Về Ssid Bạn Cần Biết |
wp-admin/includes/meta-boxes.php:post_submit_meta_box() | Displays post submit khung fields. |
wp-includes/general-template.php:get_calendar() | Display calendar with days that have posts as links. |
wp-includes/class-wp-query.php:WP_Query::get_posts() | Retrieves an array of posts based on query variables. |
wp-includes/functions.php:date_i18n() | Retrieves the date in localized format, based on a sum of Unix timestamp & timezone offset in seconds. |
wp-includes/link-template.php:get_month_link() | Retrieves the permalink for the month archives with year. |
wp-includes/link-template.php:get_day_link() | Retrieves the permalink for the day archives with year & month. |
wp-includes/link-template.php:get_year_link() | Retrieves the permalink for the year archives. |
wp-includes/class-wp-date-query.php:WP_Date_Query::build_mysql_datetime() | Builds a MySQL format date/time based on some query parameters. |
wp-includes/post.php:wp_insert_post() | Insert or update a post. |
wp-includes/post.php:wp_update_post() | Update a post with new post data. |
wp-includes/ms-functions.php:wpmu_log_new_registrations() | Logs the user email, IP, and registration date of a new site. |
wp-includes/ms-functions.php:wpmu_activate_signup() | Activate a signup. |
wp-includes/ms-functions.php:wpmu_signup_blog() | Record site signup information for future activation. |
wp-includes/ms-functions.php:wpmu_signup_user() | Record user signup information for future activation. |
wp-includes/ms-blogs.php:wpmu_update_blogs_date() | Update the last_updated field for the current site. |
wp-includes/class-wp-xmlrpc-server.php:wp_xmlrpc_server::blogger_newPost() | Creates new post. |
wp-includes/comment.php:wp_new_comment() | Adds a new phản hồi to the database. |
wp-includes/comment.php:wp_insert_comment() | Inserts a phản hồi into the database. |
Top ↑
5.3.0 | Now returns an integer if $type is "U". Previously a string was returned. |
1.0.0 | Introduced. |
Top ↑
When working with time functions, you must use current_time("timestamp") NOT time().
current_time("timestamp") return blog specific timestamp that is mix under Settings->General.time() return the time based on date.timezone setting from php.ini.
Conclusion:time() !== current_time("timestamp") // There is a big chance that they are not equal