How to solve the date time difference problem in PHP. The date (Y-m-dH: I: s) is not the same as the actual time. So I found the relevant information and found out the reason. The reason for this phenomenon: since php5.1.0, the time of date ("Y-m-d H: I: s") is always the same as the actual time. So I found the relevant information and found out the reason.
Reasons for this phenomenon:
From php5.1.0, the date. timezone option is added to php. ini, which is disabled by default, that is, the displayed time zone. By default, the Greenwich mean time and our time (Beijing time) are exactly eight hours different.
Solution:
1. the simplest method is not to use php5.1 or a later version.
2. modify the php. ini configuration file.
You can search for date. timezone in php. ini and modify it.
In Windows, php. ini is generally stored in C:/WINDOWS/php. ini.
In Linux, php. ini is generally in:/etc/php. ini
Follow the prompts above to find the date. timezone line under php. ini. if you cannot find it, you can add it yourself. Remove the semicolon and change it to date. timezone = "Asia/Shanghai". remember to restart the http service (such as apache2 or iis.
Date. timezone values following the semicolon (;) are referenced,
Available values in mainland China: Asia/Chongqing, Asia/Shanghai, Asia/Urumqi (in the order of Chongqing, Shanghai, and Urumqi)
Available in Hong Kong and Taiwan regions: Asia/Macao, Asia/Hong_Kong, Asia/Taipei (in the order of Macao, Hong Kong, and Taipei)
Singapore: Asia/Singapore
Foreigners seem to have missed Beijing
Other available values are: Etc/GMT-8, Singapore, Hongkong, PRC
What is PRC? PRC is from the People's Republic of China.
3. if you must use php5.1 or a later version, you cannot modify the php. ini configuration file.
(1) add 8 hours to the PHP code processing time to get the correct China time date ('Y-m-d H: I: S', time () + 8*3600 );
(2) add date_default_timezone_set (XXX) to the time initialization statement, or use date_default_timezone_set (XXX) in the page header) set my default time zone to date_default_timezone_set ('Asia/Shanghai.
The format string can recognize the strings of the following format parameters
Format
--
D. The day of the month, which has two numbers from the leading zero, 01 to 31.
D. The day of the week. The text indicates the three letters Mon to Sun.
The day of month j, with no leading zeros 1 to 31
L ("L" lowercase letter) day of the week, complete text format Sunday to Saturday
N ISO-8601 format number represents the day of the week (PHP 5.1.0 plus) 1 (representing Monday) to 7 (representing Sunday)
The suffix of S after the number of days per month. it can contain 2 characters including st, nd, rd, and th. Can be used with j
The day of the week. The number indicates 0 (Sunday) to 6 (Saturday)
Day 0 to 365 in year z
Week --
The week of the year in W ISO-8601 format, starting from Monday each week (new in PHP 4.1.0) for example: 42 (42nd weeks of the year)
Month --
F month, complete text format, such as January or March January to December
The month represented by m numbers, with a leading zero from 01 to 12
M: The month Jan to Dec.
N indicates the month with no leading zeros 1 to 12.
T the number of days in a given month from 28 to 31
Year --
L whether it is a leap year. if it is a leap year, it is 1; otherwise, it is 0.
O ISO-8601 format year number. This is the same as Y, except that the week number (W) of ISO belongs to the previous year or the next year. (New PHP 5.1.0) Examples: 1999 or 2003
The year in which the four digits of Y are complete, for example, 1999 or 2003.
The year represented by y two digits, for example, 99 or 03.
Time --
A lower-case morning and afternoon values: am or pm
A capital value of AM and PM
B Swatch Internet standard: 000 to 999
G-hour, 12-hour format, no leading zero 1 to 12
G-hour, in 24-hour format, no leading 0 to 23
H-hour, 12-hour format, with a leading value of 0 to 12
H-Hour, in 24-hour format, with a leading zero 00 to 23
I have the number of minutes leading to zero from 00 to 59>
S seconds, with a leading zero 00 to 59>
Time zone --
E time zone identifier (new in PHP 5.1.0) for example: UTC, GMT, Atlanta/Azores
When I is running or not, if it is running, it is 1; otherwise, it is 0.
O hours different from Greenwich Mean Time, for example: + 0200
The difference between P and Greenwich Mean Time (GMT). the hour and minute are separated by a colon (new in PHP 5.1.3), for example: +
T the Time zone of the local machine, for example, EST and MDT ([note] in Windows, the full text format, for example, "Eastern Standard Time", the Chinese version will display "China Standard Time ").
The number of seconds of the Z time difference offset. The time zone offset to the west of UTC is always negative, and the time zone offset to the east of UTC is always positive. -43200 to 43200
Complete date/time --
Date in c ISO 8601 format (new PHP 5): 19: 21 + 00: 00
Date in RFC 822 format: Thu, 21 Dec 2000 16:01:07 + 0200
The number of seconds since the Unix epoch (January 1 1970 00:00:00 GMT). For more information, see time ()
Classification: PHP
The expiration date (Y-m-d H: I: s) time is always different from the actual time. So I found the relevant information and found out the reason. Cause: php5.1.0 and later ,...