date_default_timezone_set() sets the time zone
1 2009-05-15 02:20:42 1 2009-05-15 02:20:42 1 2009-05-14 18:20:42 1 2009-05-15 10:20:42 1 2009-05-15 10:20:42
There was a remaining problem before, which is the time returned by echo date("y-m-d h:i:s",time()) It always fails to match the actual time. Today I finally found the reason and solution online. I share it as follows:
I would like to add that I modified php.ini according to the following tips and could not find the date.timezone line. It is There's nothing you can do about it, of course not, haha, if you don't have it, just add it yourself, and make enough food and clothing by yourself. I added date.timezone = "PRC" and the problem was solved. I am happy.
Starting from php5.1.0, the date.timezone option has been added to php.ini, which is turned off by default
That is, the displayed time (no matter what php command is used) is Greenwich Mean Time
It is exactly 8 hours different from our time (Beijing time). There are three methods below to restore the normal time.
1. The simplest way is not to use php5.1 or above.
2. If you must use it and cannot modify php.ini, you need to add
above the statement about time initialization. Date_default_timezone_set (XXX);
cp does not have this problem
3, once and for all, only php.ini can be modified. Open php.ini and search for date.timezone. Remove the semicolon in front
= and add XXX after it. Restart the http service (such as apache2 or iis, etc.)
Regarding XXX, the available values for mainland China are: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (in order Chongqing, Shanghai, Urumqi)
Available in Hong Kong and Taiwan: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in order Macau, Hong Kong, Taipei)
and Singapore :Asia/Singapore
Foreigners seem to have missed Beijing
Other available values are: Etc/GMT-8, Singapore, Hongkong, PRC
What is PRC? PRC is the People's Republic of China-_-
----------------------------------------- -------------------------------------------------- --------------------------
Solution:
Use date_default_timezone_set() in the header to set my default time zone It is Beijing time
date_default_timezone_set('PRC');
echo date('Y-m-d H:i:s');
The time is the same as the current time of the server!! Congratulations
Attachment The usage of date_default_timezone_set is as follows
--------------------------------
date_default_timezone_set
(PHP 5 > = 5.1.0RC1)
date_default_timezone_set -- Set the default time zone for all date and time functions in a script
Description
bool date_default_timezone_set (string timezone_identifier)
date_default_timezone_set() Set for all dates The default time zone for time functions.
Note: Since PHP 5.1.0 (the date and time functions have been rewritten in this version), if the time zone is illegal, each call to the date and time function will generate an E_NOTICE level error message.
Parameters
timezone_identifier
Time zone identifier, such as UTC or Europe/Lisbon
Return value
This function always returns TRUE (even if the timezone_identifier parameter is illegal).
-------------------------------------------------- --------------------------------------------------
Attach the time zone Identifier:
CET
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
Factory
GB
GB-Eire
GMT
GMT+0
GMT-0
GMT0
Greenwich
Hongkong
HST
Iceland
Iran
Israel
Jamaica
Japan
Kwajalein
Libya
MET
MST
MST7MDT
Navajo
NZ
NZ- CHAT
Poland
Portugal
PRC
PST8PDT
ROC
ROK
Singapore
Turkey
UCT
Universal
UTC
W- SU
WET
The above is the detailed content of Time zone setting date_default_timezone_set(). For more information, please follow other related articles on the PHP Chinese website!

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool