Đô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). 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 $timezone_identifier ). tham số : $timezone_identifier bạn lấy ở đây: http://php.net/manual/en/timezones.asia.php phù hợp khu vực bạn muốn ví dụ mình muốn set lấy giờ việt nam mình làm như sau:
date_default_timezone_set('Asia/Ho_Chi_Minh'). Sau đó
các bạn dùng hàm : echo date('d/m/Y - H:i:s'); ra đú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(). 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. Warning Please do not use any of the timezones listed here (besides UTC), they only exist for backward compatible reasons, and may expose erroneous behavior. Furthermore, these timezones may be removed from the IANA timezone database at any time. Warning
If you disregard the above warning, please also note that the IANA timezone database that provides PHP's timezone support uses POSIX style signs, which results in the
Etc/GMT+n and Etc/GMT-n time zones being reversed from common usage. For example, the time zone 8 hours ahead of GMT that is used in China and Western Australia (among other places) is actually Etc/GMT-8 in this database, not Etc/GMT+8 as you would normally expect. Once again, it is strongly recommended that you use the correct time zone for your location, such as Asia/Shanghai or Australia/Perth for the above examples. Others
Africa/Asmera
| Africa/Timbuktu
| America/Argentina/ComodRivadavia
| America/Atka
| America/Buenos_Aires
| America/Catamarca
| America/Coral_Harbour
| America/Cordoba
| America/Ensenada
| America/Fort_Wayne
| America/Godthab
| America/Indianapolis
| America/Jujuy
| America/Knox_IN
| America/Louisville
| America/Mendoza
| America/Montreal
| America/Porto_Acre
| America/Rosario
| America/Santa_Isabel
| America/Shiprock
| America/Virgin
| Antarctica/South_Pole
| Asia/Ashkhabad
| Asia/Calcutta
| Asia/Chongqing
| Asia/Chungking
| Asia/Dacca
| Asia/Harbin
| Asia/Istanbul
| Asia/Kashgar
| Asia/Katmandu
| Asia/Macao
| Asia/Rangoon
| Asia/Saigon
| Asia/Tel_Aviv
| Asia/Thimbu
| Asia/Ujung_Pandang
| Asia/Ulan_Bator
| Atlantic/Faeroe
| Atlantic/Jan_Mayen
| Australia/ACT
| Australia/Canberra
| Australia/Currie
| Australia/LHI
| Australia/North
| Australia/NSW
| Australia/Queensland
| Australia/South
| Australia/Tasmania
| Australia/Victoria
| Australia/West
| Australia/Yancowinna
| Brazil/Acre
| Brazil/DeNoronha
| Brazil/East
| Brazil/West
| Canada/Atlantic
| Canada/Central
| Canada/Eastern
| Canada/Mountain
| Canada/Newfoundland
| Canada/Pacific
| Canada/Saskatchewan
| Canada/Yukon
| CET
| Chile/Continental
| Chile/EasterIsland
| CST6CDT
| Cuba
| EET
| Egypt
| Eire
| EST
| EST5EDT
| Etc/GMT
| Etc/GMT+0
| Etc/GMT+1
| Etc/GMT+10
| Etc/GMT+11
| Etc/GMT+12
| Etc/GMT+2
| Etc/GMT+3
| Etc/GMT+4
| Etc/GMT+5
| Etc/GMT+6
| Etc/GMT+7
| Etc/GMT+8
| Etc/GMT+9
| Etc/GMT-0
| Etc/GMT-1
| Etc/GMT-10
| Etc/GMT-11
| Etc/GMT-12
| Etc/GMT-13
| Etc/GMT-14
| Etc/GMT-2
| Etc/GMT-3
| Etc/GMT-4
| Etc/GMT-5
| Etc/GMT-6
| Etc/GMT-7
| Etc/GMT-8
| Etc/GMT-9
| Etc/GMT0
| Etc/Greenwich
| Etc/UCT
| Etc/Universal
| Etc/UTC
| Etc/Zulu
| Europe/Belfast
| Europe/Kiev
| Europe/Nicosia
| Europe/Tiraspol
| Factory
| GB
| GB-Eire
| GMT
| GMT+0
| GMT-0
| GMT0
| Greenwich
| Hongkong
| HST
| Iceland
| Iran
| Israel
| Jamaica
| Japan
| Kwajalein
| Libya
| MET
| Mexico/BajaNorte
| Mexico/BajaSur
| Mexico/General
| MST
| MST7MDT
| Navajo
| NZ
| NZ-CHAT
| Pacific/Enderbury
| Pacific/Johnston
| Pacific/Ponape
| Pacific/Samoa
| Pacific/Truk
| Pacific/Yap
| Poland
| Portugal
| PRC
| PST8PDT
| ROC
| ROK
| Singapore
| Turkey
| UCT
| Universal
| US/Alaska
| US/Aleutian
| US/Arizona
| US/Central
| US/East-Indiana
| US/Eastern
| US/Hawaii
| US/Indiana-Starke
| US/Michigan
| US/Mountain
| US/Pacific
| US/Samoa
| UTC
| W-SU
| WET
| Zulu
|
There are no user contributed notes for this page.
|