mysql2date()
mysql2date( string $format, string $date, bool $transla…
mysql2date( string $format, string $date, bool $translate = true )
将给定的MySQL日期字符串转换为其他格式。
Convert given MySQL date string into a different format.
目录锚点:#说明#参数#返回#源码#笔记
说明(Description)
$format应该是PHP日期格式字符串。“U”和“G”格式将返回带时区偏移量的时间戳总和。$date应该是MySQL格式的本地时间(Y-m-d H:i:s)。
历史上,UTC时间可以传递给函数以生成Unix时间戳。
如果$translate为true,则给定的日期和格式字符串将传递给wp_date()进行转换。
参数(Parameters)
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| $format | (string) | 必需 | 返回日期的格式。 |
| $date | (string) | 必需 | 要转换的日期字符串。 |
| $translate | (bool) | 可选 | 是否应翻译返回日期。 |
返回(Return)
(string|int|false)格式化的日期string或Unix时间戳和时区偏移量之和。失败时为False。
源码(Source)
/**
* Convert given date string into a different format.
*
* $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.
*
* @since 0.71
*
* @param string $format Format of the date to return.
* @param string $date Date string to convert.
* @param bool $translate Whether the return date should be translated. Default true.
* @return string|int|bool Formatted date string or Unix timestamp. False if $date is empty.
*/
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 );
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 0.71 | wp-includes/functions.php:30 | 30 | 2 |
笔记(Notes)
基本示例
MySQL日期转换
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。

还没有任何评论,赶紧来占个楼吧!