In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces the solution of the difference between the php display time and the actual time, the article is very detailed, has a certain reference value, interested friends must read it!
Solution: 1, use "ini_set ('date.timezone','PRC')" to set the time zone; 2, use "date_default_timezone_set (' PRC')" to set the time zone; 3, set "date.timezone=PRC" in the configuration file.
Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
In PHP, the display time is inconsistent with the actual time because the time zone is set incorrectly.
The world is divided into 24 time zones, each of which has its own local time. At the same time, the local time of each time zone differs by 1: 23 hours. For example, the difference between London local time and Beijing local time is 8 hours.
To set the display time the same as the actual time, you need to set the time zone to the local time zone. Here are some common time zone identifiers and their meanings:
Asia/Shanghai-- Shanghai
Asia/Chongqing-Chongqing
Asia/Urumqi-Urumqi
Asia/Hong_Kong-Hong Kong
Asia/Macao-Macau
Asia/Taipei-Taipei
Asia/Singapore-Singapore
PRC-China time zone
Note: in China, we can set the time zone to "Asia/Shanghai" or "PRC". Remember to restart the server after the setting is successful.
Let's look at how to set the time zone:
Method 1: use the ini_set () function to set the time zone
The ini_set () function in PHP sets the value of the specified configuration option, which remains at the new value when the script runs and is restored at the end of the script. The syntax format of the function is as follows:
Ini_set ($varname, $newvalue)
Where $varname is the configuration option to be modified, and $newvalue is the new value of the configuration option.
Example:
Output result:
Method 2: use the date_default_timezone_set () function to set the time zone
The date_default_timezone_set () function in PHP sets a default time zone for all time and date functions in the script, and its syntax format is as follows:
Date_default_timezone_set ($timezone_identifier)
The parameter $timezone_identifier is a time zone identifier, such as UTC (Greenwich mean time) or Europe/Lisbon (Portugal).
Since PHP5.1.0 (this version of the date-time function has been rewritten), every call to the date-time function generates an E_NOTICE-level error message if the time zone is illegal, and an E_STRICT-level message if the system settings or TZ environment variables are used.
Example:
Output result:
Method 3: set it in the configuration file php.ini
The configuration file for PHP is the php.ini file in the PHP installation directory, find it and open it. Then search for date.timezone in the file, and we will see a piece of information like this:
[Date]; Defines the default timezone used by the date functions; http://php.net/date.timezone;date.timezone =
Where; date.timezone = preceding; the same function as / / in PHP, both mean comments. Here, we need to remove this; and fill in the corresponding time zone identifier after the = in this sentence, as shown below:
[Date]; Defines the default timezone used by the date functions; http://php.net/date.timezonedate.timezone = PRC
Extended knowledge: time zone identifiers that can be set in Asia
Asia/AdenAsia/AlmatyAsia/AmmanAsia/AnadyrAsia/AqtauAsia/AqtobeAsia/AshgabatAsia/AtyrauAsia/BaghdadAsia/BahrainAsia/BakuAsia/BangkokAsia/BarnaulAsia/BeirutAsia/BishkekAsia/BruneiAsia/ChitaAsia/ChoibalsanAsia/ColomboAsia/DamascusAsia/DhakaAsia/DiliAsia/DubaiAsia/DushanbeAsia/FamagustaAsia/GazaAsia/HebronAsia/Ho_Chi_MinhAsia/Hong_KongAsia/HovdAsia/IrkutskAsia/JakartaAsia/JayapuraAsia/JerusalemAsia/KabulAsia/KamchatkaAsia/KarachiAsia/KathmanduAsia/KhandygaAsia/KolkataAsia/KrasnoyarskAsia/Kuala_LumpurAsia/KuchingAsia/KuwaitAsia/MacauAsia/MagadanAsia/MakassarAsia/ManilaAsia/MuscatAsia/NicosiaAsia/NovokuznetskAsia/NovosibirskAsia/OmskAsia/OralAsia/Phnom_ PenhAsia/PontianakAsia/PyongyangAsia/QatarAsia/QostanayAsia/QyzylordaAsia/RiyadhAsia/SakhalinAsia/SamarkandAsia/SeoulAsia/ShanghaiAsia/SingaporeAsia/SrednekolymskAsia/TaipeiAsia/TashkentAsia/TbilisiAsia/TehranAsia/ThimphuAsia/TokyoAsia/TomskAsia/UlaanbaatarAsia/UrumqiAsia/Ust-NeraAsia/VientianeAsia/VladivostokAsia/YakutskAsia/YangonAsia/YekaterinburgAsia/Yerevan
The above is all the contents of this article entitled "the solution to the difference between php display time and actual time". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.