henshall / timezones
此包的最新版本(dev-master)没有可用的许可证信息。
适用于 mysql 时区表的包
dev-master
2020-05-03 14:31 UTC
This package is auto-updated.
Last update: 2024-09-19 22:47:29 UTC
README
版本:1.0.0
这是一个简单的时区包,用于与 php 和 mysql 时区表一起使用。它允许您获取当前时区、获取任何时区的当前时间,并生成所有可能时区及其当前时间的列表。这对于需要知道用户所在时区的应用程序(如调度应用程序)非常有用。
安装
- 安装 mysql 的时区表
- 运行 composer require henshall\timezones
使用方法
使用此方法获取和设置您的本地时区。请阅读以下有关设置时区的说明。
$timezone = new Timezone("localhost", "username", "password", "database_name", "local_timezone(optional)"); $timezone->set_local_timezone("Europe/Moscow"); $local_timezone = $timezone->get_local_timezone();
获取所有时区及其当前时间的数组
$timezone = new Timezone("localhost", "username", "password", "database_name", "local_timezone(optional)"); $timezone->get_timezones_and_current_times()
获取特定时区的本地当前时间
$timezone = new Timezone("localhost", "username", "password", "database_name", "local_timezone(optional)"); $japan_time = $timezone->get_time_now("Japan");
说明
- 您的计算机时钟必须设置正确。如果您的时钟设置不正确,时区计算将不正确。
- 本地时区(通过 get_local_timezone() 查找)必须是您的当前时区。如果时区设置不正确,计算也将不正确。
- 此应用程序将自动使用 mysql 表确定您的当前时区,如果它设置不正确,您可能需要手动设置,如上述示例所示。