函数文档

wp_timezone()

💡 云策文档标注

概述

wp_timezone() 函数用于获取站点的时区,返回一个 DateTimeZone 对象。它基于 wp_timezone_string() 函数实现,适用于 WordPress 开发中的时间处理场景。

关键要点

  • 返回类型为 DateTimeZone 对象,可直接用于 PHP 的日期时间操作。
  • 时区可以基于 PHP 时区字符串或 ±HH:MM 偏移量设置。
  • 函数在 WordPress 5.3.0 版本中引入。
  • 与多个时间相关函数关联,如 wp_timezone_string()、current_datetime()、wp_date() 等。

代码示例

function wp_timezone() {
    return new DateTimeZone( wp_timezone_string() );
}

📄 原文内容

Retrieves the timezone of the site as a DateTimeZone object.

Description

Timezone can be based on a PHP timezone string or a ±HH:MM offset.

Return

DateTimeZone Timezone object.

Source

function wp_timezone() {
	return new DateTimeZone( wp_timezone_string() );
}

Changelog

Version Description
5.3.0 Introduced.