函数原型
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.
是否弃用
未弃用
函数参数
-
$string
string
Required - The date to be converted, in the timezone of the site.
-
$format
string
Optional - The format string for the returned date.
Default:
'Y-m-d H:i:s'
函数返回值
string Formatted version of the date, in UTC.
函数位置
File: wp-includes/formatting.php.
函数源码
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 );
}
源码链接
变更日志
| Version | Description |
|---|---|
| 1.2.0 | Introduced. |

