In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to complete the time zone setting in PHP". The explanation in the article is simple and clear and easy to learn and understand. Please follow the editor's train of thought to study and learn "how to complete the time zone setting in PHP".
In our daily life, time is very important and indispensable, and the same is true in PHP. In our daily development, sometimes when time needs to be saved to record something, how should we set the time?
In PHP, you can get the date and time through the time function of the date. The date and time function in PHP is set by the time of the server, which defaults to Greenwich mean time.
Setting of time zone in PHP
To change the time in PHP to local time, you need to change the time zone setting in the PHP language. There are three ways to set the time zone of a language in PHP. Let's take a look at this:
Configure in the configuration file
The configuration file in PHP is the php.ini file. As for how to find this file, I wrote "how do I upload a file in PHP?" After reading it, you will understand! "as mentioned in, if you are interested, you can click to check it out. After finding php.ini, look for date.timezone in the file and find the following result:
Where Asia/Shangha represents the time zone, also known as the time zone identifier. There are many such time zone identifiers. Here are some commonly used time zone identifiers:
Asia/Shanghai-- Shanghai
Asia/Chongqing-Chongqing
Asia/Hong_Kong-Hong Kong
Asia/Macao-Macau
Asia/Taipei-Taipei
PRC-China time zone
It is important to note that when our time zone setting is complete, we need to restart the server for the lost settings to take effect.
Use the date_default_timezone_set () function to set the time zone
In PHP, the date_default_timezone_set () function can set a default time zone for all date functions, and its syntax format is as follows:
Date_default_timezone_set (time zone identifier)
Examples are as follows:
Output result:
As can be seen from the above results, a time zone can be set through the date_default_timezone_set () function.
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 maintains the new value when the script runs and restores it at the end of the script. The syntax format of the function is as follows:
Ini_set (option to be modified, the new value of this option)
Examples are as follows:
Output result:
As you can see from the listing example, when the script resumes, reconfigure a new option, and the set time zone option remains at the new value.
Thank you for your reading, the above is the content of "how to complete the time zone setting in PHP". After the study of this article, I believe you have a deeper understanding of how to complete the time zone setting in PHP, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.