Hướng dẫn uae timezone php - uae múi giờ php

I am using yii framework

I am using below to code to get time


how can i current time of

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
2?

Hướng dẫn uae timezone php - uae múi giờ php

Insane Skull

9,1459 gold badges44 silver badges61 bronze badges9 gold badges44 silver badges61 bronze badges

asked Dec 29, 2015 at 11:18Dec 29, 2015 at 11:18

Try this:

$tz = 'Asia/Dubai'; // your required location time zone.
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $dt->format('Y/m/d H:i:s');

John C

8,0832 gold badges36 silver badges46 bronze badges2 gold badges36 silver badges46 bronze badges

answered Dec 29, 2015 at 11:25Dec 29, 2015 at 11:25

MohammadMohammadMohammad

3,3315 gold badges51 silver badges74 bronze badges5 gold badges51 silver badges74 bronze badges

Use date_default_timezone_set() :

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');

answered Dec 29, 2015 at 11:35Dec 29, 2015 at 11:35

Hướng dẫn uae timezone php - uae múi giờ php

Insane SkullInsane SkullInsane Skull

9,1459 gold badges44 silver badges61 bronze badges9 gold badges44 silver badges61 bronze badges

Đạo lúcc các bạn xem các hướng dẫn về ha lấy thời gian: ngày (định dạng, dấu thời gian).date(format,timestamp).

Nếu chưa biết ha date (định dạng, dấu thời gian) bạn đó là thể xem ở link: http: //congnghe5s.com/bai-viet/xu-ly-ngay

Bạn thực hiện kiểm tra lệnh trênn máiy và kết quả không khớp với thời gian hiện tại. ĐÓ Là Vì lí do thời Gian Hay Timezone Trênn Server Bạn Đạo Caoi

Cú Pháp: Date_Default_Timezone_set & nbsp; (& nbsp; chuỗi & nbsp; ________ 23 & nbsp;).ú pháp:date_default_timezone_set ( string 

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
3 ).

Tham Số: $ ________ 24http: //php.net/manual/en/timezones.asia.php

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
4http://php.net/manual/en/timezones.asia.php

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
5

date_default_timezone_set('Asia/Ho_Chi_Minh').Asia/Ho_Chi_Minh').

Sau Đói Các bạn Dùng Hàm: & nbsp; Echo Date ('d/m/y - h: i: s');echo date('d/m/Y - H:i:s');

RA Đúng Kết Quả Thời gian ở Việt Nam.đúng kết quả time ở Việt Nam.

Ví dụ:

date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');

Ví dụ trên bạn 1 ha cũng Khá quan trọng: & nbsp; date_default_timezone_get () & nbsp; & nbsp;date_default_timezone_get()  trả về timezone mặc định của server bạn đang chạy hoặc là đã được thiết lập thông qua date_default_timezone_set().

Qua bào viết hy vọng các bạn đó là thêm kiến ​​thức khi

Đạo lúcc các bạn xem các hướng dẫn về ha lấy thời gian: ngày (định dạng, dấu thời gian).date(format,timestamp).

Nếu chưa biết ha date (định dạng, dấu thời gian) bạn đó là thể xem ở link: http: //congnghe5s.com/bai-viet/xu-ly-ngay

Bạn thực hiện kiểm tra lệnh trênn máiy và kết quả không khớp với thời gian hiện tại. ĐÓ Là Vì lí do thời Gian Hay Timezone Trênn Server Bạn Đạo Caoi

Cú Pháp: Date_Default_Timezone_set & nbsp; (& nbsp; chuỗi & nbsp; ________ 23 & nbsp;).ú pháp:date_default_timezone_set ( string 

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
3 ).

Tham Số: $ ________ 24http: //php.net/manual/en/timezones.asia.php

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
4http://php.net/manual/en/timezones.asia.php

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
5

date_default_timezone_set('Asia/Ho_Chi_Minh').Asia/Ho_Chi_Minh').

Sau Đói Các bạn Dùng Hàm: & nbsp; Echo Date ('d/m/y - h: i: s');echo date('d/m/Y - H:i:s');

RA Đúng Kết Quả Thời gian ở Việt Nam.đúng kết quả time ở Việt Nam.

Ví dụ:

date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');

Ví dụ trên bạn 1 ha cũng Khá quan trọng: & nbsp; date_default_timezone_get () & nbsp; & nbsp;date_default_timezone_get()  trả về timezone mặc định của server bạn đang chạy hoặc là đã được thiết lập thông qua date_default_timezone_set().

Qua bài viết hy vọng các bạn có thêm kiến thức khi xử lý ngày tháng trong PHP.

Đôi lúc các bạn xem các hướng dẫn về hàm lấy thời gian :date(format,timestamp).date(format,timestamp).

Nếu chưa biết hàm date(format,timestamp) bạn có thể xem ở link:http://congnghe5s.com/bai-viet/xu-ly-ngay-gio-trong-php.html.

Bạn thực hiện test lệnh trên máy và kết quả không khớp với time hiện tại. Đó là vì lí do thời gian hay timezone trên server bạn đã cài đặt khác vì thế để trả về đúng time bạn muốn bạn có thể dùng hàm:

Cú pháp:date_default_timezone_set ( string 

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
3 ).ú pháp:date_default_timezone_set ( string 
date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
3
 ).

tham số : $

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
4http://php.net/manual/en/timezones.asia.php
date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
4http://php.net/manual/en/timezones.asia.php

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
5

date_default_timezone_set('Asia/Ho_Chi_Minh').Asia/Ho_Chi_Minh').

Sau đó các bạn dùng hàm : echo date('d/m/Y - H:i:s');echo date('d/m/Y - H:i:s');

ra đúng kết quả time ở Việt Nam.đúng kết quả time ở Việt Nam.

Ví dụ:

date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');

Ví dụ trên có 1 hàm cũng khá quan trọng : date_default_timezone_get()  trả về timezone mặc định của server bạn đang chạy hoặc là đã được thiết lập thông qua date_default_timezone_set().date_default_timezone_get()  trả về timezone mặc định của server bạn đang chạy hoặc là đã được thiết lập thông qua date_default_timezone_set().

Qua bài viết hy vọng các bạn có thêm kiến thức khi xử lý ngày tháng trong PHP.

5.1.15 MySQL Server Time Zone Support

This section describes the time zone settings maintained by MySQL, how to load the system tables required for named time support, how to stay current with time zone changes, and how to enable leap-second support.

Beginning with MySQL 8.0.19, time zone offsets are also supported for inserted datetime values; see Section 11.2.2, “The DATE, DATETIME, and TIMESTAMP Types”, for more information.

For information about time zone settings in replication setups, see Section 17.5.1.14, “Replication and System Functions” and Section 17.5.1.33, “Replication and Time Zones”.

  • Time Zone Variables

  • Populating the Time Zone Tables

  • Staying Current with Time Zone Changes

  • Time Zone Leap Second Support

Time Zone Variables

Populating the Time Zone Tables

  • Staying Current with Time Zone Changes

    Time Zone Leap Second Supportmysqld. If you start the server using mysqld_safe, its

    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    4 option provides another way to set the system time zone. The permissible values for
    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    3 and
    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    4 are system dependent. Consult your operating system documentation to see what values are acceptable.

  • MySQL Server maintains several time zone settings:

    The server system time zone. When the server starts, it attempts to determine the time zone of the host machine and uses it to set the

    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    2 system variable.

    To explicitly specify the system time zone for MySQL Server at startup, set the

    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    3 environment variable before you start mysqld. If you start the server using mysqld_safe, its
    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    4 option provides another way to set the system time zone. The permissible values for
    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    3 and
    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    4 are system dependent. Consult your operating system documentation to see what values are acceptable.

    The server current time zone. The global

    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    7 system variable indicates the time zone the server currently is operating in. The initial
    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    7 value is
    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    9, which indicates that the server time zone is the same as the system time zone.

    default-time-zone='timezone'

    Note

    SET GLOBAL time_zone = timezone;
  • If set to

    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    0, every MySQL function call that requires a time zone calculation makes a system library call to determine the current system time zone. This call may be protected by a global mutex, resulting in contention.

    SET time_zone = timezone;

The initial global server time zone value can be specified explicitly at startup with the

date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');
1 option on the command line, or you can use the following line in an option file:

If you have the

date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');
2 privilege (or the deprecated
date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');
3 privilege), you can set the global server time zone value at runtime with this statement:

Per-session time zones. Each client that connects has its own session time zone setting, given by the session

date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');
7 variable. Initially, the session variable takes its value from the global
date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');
7 variable, but the client can change its own time zone with this statement:

SELECT @@GLOBAL.time_zone, @@SESSION.time_zone;

Các giá trị

date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');
8 có thể được đưa ra ở một số định dạng, không có giá trị nào nhạy cảm với trường hợp:

  • Vì giá trị

    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    9, chỉ ra rằng múi giờ của máy chủ giống như múi giờ hệ thống.

  • Là một chuỗi chỉ ra một phần bù từ UTC của Mẫu ____ 60] ________ 61: ________ 62, có tiền tố với

    default-time-zone='timezone'
    3 hoặc
    default-time-zone='timezone'
    4, chẳng hạn như
    default-time-zone='timezone'
    5,
    default-time-zone='timezone'
    6 hoặc
    default-time-zone='timezone'
    7. Một số 0 hàng đầu có thể được sử dụng một cách tùy chọn cho các giá trị giờ dưới 10; MySQL chuẩn bị số 0 hàng đầu khi lưu trữ và truy xuất giá trị trong những trường hợp như vậy. MySQL chuyển đổi
    default-time-zone='timezone'
    8 hoặc
    default-time-zone='timezone'
    9 thành
    SET GLOBAL time_zone = timezone;
    0.

    Trước MySQL 8.0.19, giá trị này phải nằm trong phạm vi

    SET GLOBAL time_zone = timezone;
    1 đến
    SET GLOBAL time_zone = timezone;
    2, bao gồm; Bắt đầu với MySQL 8.0.19, phạm vi được phép là
    SET GLOBAL time_zone = timezone;
    3 đến
    SET GLOBAL time_zone = timezone;
    4, bao gồm.

  • Là một múi giờ được đặt tên, chẳng hạn như

    SET GLOBAL time_zone = timezone;
    5,
    SET GLOBAL time_zone = timezone;
    6,
    SET GLOBAL time_zone = timezone;
    7 hoặc
    SET GLOBAL time_zone = timezone;
    8.

    Ghi chú

    Các múi giờ được đặt tên chỉ có thể được sử dụng nếu các bảng thông tin múi giờ trong cơ sở dữ liệu

    SET GLOBAL time_zone = timezone;
    9 đã được tạo và điền vào. Mặt khác, việc sử dụng múi giờ được đặt tên dẫn đến lỗi:

    $tz = 'Asia/Dubai'; // your required location time zone.
    $timestamp = time();
    $dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
    $dt->setTimestamp($timestamp); //adjust the object to correct timestamp
    echo $dt->format('Y/m/d H:i:s');
    
    0

Điền vào các bảng múi giờ

Một số bảng trong lược đồ hệ thống

SET GLOBAL time_zone = timezone;
9 tồn tại để lưu trữ thông tin múi giờ (xem Phần & NBSP; 5.3, Lược đồ hệ thống MySQL). Quy trình cài đặt MySQL tạo các bảng múi giờ, nhưng không tải chúng. Để làm như vậy bằng tay, sử dụng các hướng dẫn sau.

Ghi chú

Các múi giờ được đặt tên chỉ có thể được sử dụng nếu các bảng thông tin múi giờ trong cơ sở dữ liệu

SET GLOBAL time_zone = timezone;
9 đã được tạo và điền vào. Mặt khác, việc sử dụng múi giờ được đặt tên dẫn đến lỗi:

Điền vào các bảng múi giờzoneinfo database (the set of files describing time zones), use the mysql_tzinfo_to_sql program to load the time zone tables. Examples of such systems are Linux, macOS, FreeBSD, and Solaris. One likely location for these files is the

SET time_zone = timezone;
1 directory. If your system has no zoneinfo database, you can use a downloadable package, as described later in this section.

Một số bảng trong lược đồ hệ thống

SET GLOBAL time_zone = timezone;
9 tồn tại để lưu trữ thông tin múi giờ (xem Phần & NBSP; 5.3, Lược đồ hệ thống MySQL). Quy trình cài đặt MySQL tạo các bảng múi giờ, nhưng không tải chúng. Để làm như vậy bằng tay, sử dụng các hướng dẫn sau.mysql_tzinfo_to_sql and send the output into the mysql program. For example:

$tz = 'Asia/Dubai'; // your required location time zone.
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $dt->format('Y/m/d H:i:s');
1

Tải thông tin múi giờ không nhất thiết phải là hoạt động một lần vì thỉnh thoảng thông tin thay đổi. Khi những thay đổi đó xảy ra, các ứng dụng sử dụng các quy tắc cũ sẽ lỗi thời và bạn có thể thấy cần phải tải lại các bảng múi giờ để giữ thông tin được sử dụng bởi máy chủ MySQL của bạn hiện tại. Xem hiện tại với thay đổi múi giờ.mysql command shown here assumes that you connect to the server using an account such as

SET time_zone = timezone;
2 that has privileges for modifying tables in the
SET GLOBAL time_zone = timezone;
9 system schema. Adjust the connection parameters as required.

Nếu hệ thống của bạn có cơ sở dữ liệu ZoneInfo riêng (tập hợp các tệp mô tả múi giờ), hãy sử dụng chương trình MySQL_TZINFO_TO_SQL để tải các bảng múi giờ. Ví dụ về các hệ thống như vậy là Linux, MacOS, FreeBSD và Solaris. Một vị trí có khả năng cho các tệp này là thư mục

SET time_zone = timezone;
1. Nếu hệ thống của bạn không có cơ sở dữ liệu ZoneInfo, bạn có thể sử dụng gói có thể tải xuống, như được mô tả sau trong phần này. reads your system's time zone files and generates SQL statements from them. mysql processes those statements to load the time zone tables.

Để tải các bảng múi giờ từ dòng lệnh, hãy truyền tên đường dẫn thư mục ZoneInfo đến mysql_tzinfo_to_sql và gửi đầu ra vào chương trình MySQL. Ví dụ: also can be used to load a single time zone file or generate leap second information:

  • Lệnh MySQL hiển thị ở đây giả định rằng bạn kết nối với máy chủ bằng tài khoản như

    SET time_zone = timezone;
    2 có đặc quyền để sửa đổi các bảng trong lược đồ hệ thống
    SET GLOBAL time_zone = timezone;
    9. Điều chỉnh các tham số kết nối theo yêu cầu.mysql_tzinfo_to_sql like this:

    $tz = 'Asia/Dubai'; // your required location time zone.
    $timestamp = time();
    $dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
    $dt->setTimestamp($timestamp); //adjust the object to correct timestamp
    echo $dt->format('Y/m/d H:i:s');
    
    2

    mysql_tzinfo_to_sql đọc các tệp múi giờ của hệ thống của bạn và tạo các câu lệnh SQL từ chúng. MySQL xử lý các câu lệnh đó để tải các bảng múi giờ.

  • mysql_tzinfo_to_sql cũng có thể được sử dụng để tải một tệp múi giờ duy nhất hoặc tạo thông tin thứ hai của bước nhảy vọt:

    $tz = 'Asia/Dubai'; // your required location time zone.
    $timestamp = time();
    $dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
    $dt->setTimestamp($timestamp); //adjust the object to correct timestamp
    echo $dt->format('Y/m/d H:i:s');
    
    3

Để tải một tệp múi giờ duy nhất

SET time_zone = timezone;
4 tương ứng với tên múi giờ
SET time_zone = timezone;
5, gọi mysql_tzinfo_to_sql như thế này:mysql_tzinfo_to_sql, restart the server so that it does not continue to use any previously cached time zone data.

Với phương pháp này, bạn phải thực thi một lệnh riêng để tải tệp múi giờ cho mỗi vùng được đặt tên mà máy chủ cần biết.

$tz = 'Asia/Dubai'; // your required location time zone.
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $dt->format('Y/m/d H:i:s');
4

Nếu múi giờ của bạn phải tính đến các giây nhảy, hãy khởi tạo thông tin thứ hai như thế này, trong đó

SET time_zone = timezone;
4 là tên của tệp múi giờ của bạn:

Sau khi chạy mysql_tzinfo_to_sql, hãy khởi động lại máy chủ để nó không tiếp tục sử dụng bất kỳ dữ liệu múi giờ được lưu trong bộ đệm trước đó.not use a downloadable time zone package if your system has a zoneinfo database. Use the mysql_tzinfo_to_sql utility instead. Otherwise, you may cause a difference in datetime handling between MySQL and other applications on your system.

Nếu hệ thống của bạn không có cơ sở dữ liệu ZoneInfo (ví dụ: Windows), bạn có thể sử dụng gói chứa các câu lệnh SQL có sẵn để tải xuống tại Khu vực phát triển MySQL:

$tz = 'Asia/Dubai'; // your required location time zone.
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $dt->format('Y/m/d H:i:s');
5

Cảnh báo

Nếu múi giờ của bạn phải tính đến các giây nhảy, hãy khởi tạo thông tin thứ hai như thế này, trong đó

SET time_zone = timezone;
4 là tên của tệp múi giờ của bạn:

Sau khi chạy mysql_tzinfo_to_sql, hãy khởi động lại máy chủ để nó không tiếp tục sử dụng bất kỳ dữ liệu múi giờ được lưu trong bộ đệm trước đó.not use a downloadable time zone package that contains

SET time_zone = timezone;
7 tables. That is intended for older MySQL versions. MySQL now uses
SET time_zone = timezone;
8 for the time zone tables. Trying to replace them with
SET time_zone = timezone;
7 tables causes problems.

Nếu hệ thống của bạn không có cơ sở dữ liệu ZoneInfo (ví dụ: Windows), bạn có thể sử dụng gói chứa các câu lệnh SQL có sẵn để tải xuống tại Khu vực phát triển MySQL:

Cảnh báo

  • Thời gian hệ điều hành ảnh hưởng đến giá trị mà máy chủ MySQL sử dụng cho thời gian nếu múi giờ của nó được đặt thành

    date_default_timezone_set('Asia/Ho_Chi_Minh');
    
    if (date_default_timezone_get()) {
        echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
    ';
    }
    echo date('d/m/Y H:i:s');
    0. Đảm bảo rằng hệ điều hành của bạn đang sử dụng thông tin múi giờ mới nhất. Đối với hầu hết các hệ điều hành, bản cập nhật hoặc gói dịch vụ mới nhất chuẩn bị hệ thống của bạn cho các thay đổi thời gian. Kiểm tra trang web cho nhà cung cấp hệ điều hành của bạn để cập nhật giải quyết các thay đổi thời gian.

  • Nếu bạn thay thế tệp múi giờ

    SELECT @@GLOBAL.time_zone, @@SESSION.time_zone;
    1 của hệ thống bằng phiên bản sử dụng các quy tắc khác với các quy tắc có hiệu lực tại MySQLD Startup, hãy khởi động lại MySQLD để nó sử dụng các quy tắc được cập nhật. Nếu không, MySQLD có thể không nhận thấy khi hệ thống thay đổi thời gian.mysqld startup, restart mysqld so that it uses the updated rules. Otherwise, mysqld might not notice when the system changes its time.

  • Nếu bạn sử dụng các múi giờ được đặt tên với MySQL, hãy đảm bảo rằng các bảng múi giờ trong cơ sở dữ liệu

    SET GLOBAL time_zone = timezone;
    9 đã được cập nhật:

    • Nếu hệ thống của bạn có cơ sở dữ liệu ZoneInfo riêng, hãy tải lại các bảng múi giờ MySQL bất cứ khi nào cơ sở dữ liệu ZoneInfo được cập nhật.

    • Đối với các hệ thống không có cơ sở dữ liệu ZoneInfo của riêng họ, hãy kiểm tra Khu vực phát triển MySQL để cập nhật. Khi có sẵn một bản cập nhật mới, hãy tải xuống và sử dụng nó để thay thế nội dung của các bảng múi giờ hiện tại của bạn.

    Để biết hướng dẫn cho cả hai phương thức, xem điền vào các bảng múi giờ. MySQLD lưu trữ thông tin múi giờ mà nó tra cứu, vì vậy sau khi cập nhật các bảng múi giờ, hãy khởi động lại MySQLD để đảm bảo rằng nó không tiếp tục phục vụ dữ liệu múi giờ lỗi thời.mysqld caches time zone information that it looks up, so after updating the time zone tables, restart mysqld to make sure that it does not continue to serve outdated time zone data.

Nếu bạn không chắc chắn liệu có sẵn các múi giờ được đặt tên, để sử dụng làm cài đặt múi giờ của máy chủ hoặc bởi các máy khách đặt múi giờ của riêng họ, hãy kiểm tra xem các bảng múi giờ của bạn có trống không. Truy vấn sau đây xác định liệu bảng có chứa tên múi giờ có bất kỳ hàng nào không:

$tz = 'Asia/Dubai'; // your required location time zone.
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $dt->format('Y/m/d H:i:s');
6

Một số 0 chỉ ra rằng bảng trống. Trong trường hợp này, hiện tại không có ứng dụng nào đang sử dụng các múi giờ được đặt tên và bạn không cần phải cập nhật các bảng (trừ khi bạn muốn bật hỗ trợ múi giờ được đặt tên). Một số lượng lớn hơn 0 chỉ ra rằng bảng không trống và nội dung của nó có sẵn để được sử dụng để hỗ trợ múi giờ được đặt tên. Trong trường hợp này, hãy chắc chắn tải lại các bảng múi giờ của bạn để các ứng dụng sử dụng các múi giờ được đặt tên có thể có được kết quả truy vấn chính xác.

Để kiểm tra xem cài đặt MySQL của bạn có được cập nhật đúng cách để thay đổi quy tắc thời gian tiết kiệm ánh sáng ban ngày hay không, hãy sử dụng thử nghiệm như sau. Ví dụ sử dụng các giá trị phù hợp với thay đổi DST 1 giờ năm 2007 xảy ra ở Hoa Kỳ vào ngày 11 tháng 3 lúc 2 giờ sáng.

Bài kiểm tra sử dụng truy vấn này:

$tz = 'Asia/Dubai'; // your required location time zone.
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $dt->format('Y/m/d H:i:s');
7

Hai giá trị thời gian cho biết thời gian thay đổi DST xảy ra và việc sử dụng các múi giờ được đặt tên yêu cầu sử dụng các bảng múi giờ. Kết quả mong muốn là cả hai truy vấn đều trả về cùng một kết quả (thời gian đầu vào, được chuyển đổi thành giá trị tương đương trong múi giờ 'Hoa Kỳ/Trung tâm').

Trước khi cập nhật các bảng múi giờ, bạn sẽ thấy một kết quả không chính xác như thế này:

$tz = 'Asia/Dubai'; // your required location time zone.
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $dt->format('Y/m/d H:i:s');
8

Sau khi cập nhật các bảng, bạn sẽ thấy kết quả chính xác:

$tz = 'Asia/Dubai'; // your required location time zone.
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $dt->format('Y/m/d H:i:s');
9

Múi giờ nhảy vọt thứ hai hỗ trợ

Giá trị thứ hai của Leap được trả về với một phần thời gian kết thúc bằng

SELECT @@GLOBAL.time_zone, @@SESSION.time_zone;
3. Điều này có nghĩa là một hàm như
date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');
6 có thể trả về cùng giá trị trong hai hoặc ba giây liên tiếp trong lần nhảy thứ hai. Vẫn đúng là các giá trị thời gian theo nghĩa đen có phần thời gian kết thúc bằng
SELECT @@GLOBAL.time_zone, @@SESSION.time_zone;
5 hoặc
SELECT @@GLOBAL.time_zone, @@SESSION.time_zone;
6 được coi là không hợp lệ.

Nếu cần phải tìm kiếm các giá trị

date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');
8 một giây trước khi bước nhảy thứ hai, có thể thu được kết quả dị thường nếu bạn sử dụng so sánh với các giá trị
SELECT @@GLOBAL.time_zone, @@SESSION.time_zone;
8 '. Ví dụ sau đây chứng minh điều này. Nó thay đổi múi giờ phiên thành UTC vì vậy không có sự khác biệt giữa các giá trị
date_default_timezone_set('Asia/Ho_Chi_Minh');

if (date_default_timezone_get()) {
    echo 'date_default_timezone_set: ' . date_default_timezone_get() . '
';
}
echo date('d/m/Y H:i:s');
8 bên trong (có trong UTC) và các giá trị được hiển thị (có hiệu chỉnh múi giờ được áp dụng).

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
0

Để làm việc xung quanh điều này, bạn có thể sử dụng một so sánh dựa trên giá trị UTC thực sự được lưu trữ trong cột, có hiệu chỉnh thứ hai bước nhảy vọt:

date_default_timezone_set('Asia/Dubai');
echo "The time is " . date('Y/m/d H:i:s');
1