返回介绍

mysql2date()

发布于 2017-09-11 01:58:42 字数 5657 浏览 840 评论 0 收藏 0

mysql2date( string $format,  string $date,  bool $translate = true )

Convert given date string into a different format.


description

$format should be either a PHP date format string, e.g. ‘U’ for a Unix timestamp, or ‘G’ for a Unix timestamp assuming that $date is GMT.

If $translate is true then the given date and format string will be passed to date_i18n() for translation.


参数

$format

(string) (Required) Format of the date to return.

$date

(string) (Required) Date string to convert.

$translate

(bool) (Optional) Whether the return date should be translated.

Default value: true


返回值

(string|int|bool) Formatted date string or Unix timestamp. False if $date is empty.


源代码

File: wp-includes/functions.php

function mysql2date( $format, $date, $translate = true ) {
	if ( empty( $date ) )
		return false;

	if ( 'G' == $format )
		return strtotime( $date . ' +0000' );

	$i = strtotime( $date );

	if ( 'U' == $format )
		return $i;

	if ( $translate )
		return date_i18n( $format, $i );
	else
		return date( $format, $i );
}

更新日志

Versiondescription
0.71Introduced.

相关函数

Uses

  • wp-includes/functions.php: date_i18n()

Used By

  • wp-includes/class-wp-customize-manager.php: WP_Customize_Manager::save_changeset_post()
  • wp-includes/comment.php: wp_check_comment_flood()
  • wp-includes/functions.php: mysql_to_rfc3339()
  • wp-admin/includes/class-wp-posts-list-table.php: WP_Posts_List_Table::column_date()
  • wp-admin/includes/class-wp-ms-sites-list-table.php: WP_MS_Sites_List_Table::column_lastupdated()
  • wp-admin/includes/class-wp-ms-sites-list-table.php: WP_MS_Sites_List_Table::column_registered()
  • wp-admin/includes/class-wp-ms-users-list-table.php: WP_MS_Users_List_Table::column_registered()
  • wp-admin/includes/class-wp-media-list-table.php: WP_Media_List_Table::column_date()
  • wp-includes/class-wp-query.php: WP_Query::setup_postdata()
  • wp-admin/includes/export.php: export_wp()
  • wp-admin/includes/template.php: get_inline_data()
  • wp-admin/includes/template.php: touch_time()
  • wp-admin/includes/media.php: get_media_item()
  • wp-admin/includes/ajax-actions.php: wp_ajax_wp_fullscreen_save_post()
  • wp-admin/includes/ajax-actions.php: wp_ajax_find_posts()
  • wp-includes/general-template.php: get_post_time()
  • wp-includes/general-template.php: get_post_modified_time()
  • wp-includes/general-template.php: the_weekday()
  • wp-includes/general-template.php: the_weekday_date()
  • wp-includes/general-template.php: wp_get_archives()
  • wp-includes/general-template.php: the_date_xml()
  • wp-includes/general-template.php: get_the_date()
  • wp-includes/deprecated.php: get_boundary_post_rel_link()
  • wp-includes/deprecated.php: get_parent_post_rel_link()
  • wp-includes/class-wp.php: WP::send_headers()
  • wp-includes/link-template.php: get_adjacent_post_link()
  • wp-includes/link-template.php: get_adjacent_post_rel_link()
  • wp-includes/class-walker-page.php: Walker_Page::start_el()
  • wp-includes/media.php: wp_prepare_attachment_for_js()
  • wp-includes/post.php: wp_insert_post()
  • wp-includes/ms-functions.php: wpmu_validate_user_signup()
  • wp-includes/ms-functions.php: wpmu_validate_blog_signup()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::wp_editPost()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_convert_date()
  • wp-includes/class-wp-xmlrpc-server.php: wp_xmlrpc_server::_convert_date_gmt()
  • wp-includes/comment-template.php: get_comment_time()
  • wp-includes/comment-template.php: get_comment_date()
  • wp-includes/class-wp-editor.php: _WP_Editors::wp_link_query()
  • Show 33 more used by Hide more used by

User Contributed Notes

  1. Skip to note content You must log in to vote on the helpfulness of this noteVote results for this note: -1You must log in to vote on the helpfulness of this note Contributed by Codex

    Basic Example

    Convert a MySQL date to a Unix timestamp:

    
    echo mysql2date( 'U', '2012-02-23 06:12:45' ); // 1329977565
    
  2. MySQL date conversion

    Convert a MySQL date to another date format:

    
    echo mysql2date( 'l, F j, Y', '2012-02-23 06:12:45' ) // Thursday, February 23, 2012
    

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文