Beginners PHP To do the site, want to get the current time on the page, learn programming people know the time function date (), first Use this function to format a local time/date, first write a test code bar, the result output time is 8 hours less than the actual time, what is the reason for this:
[PHP]
echo Date (' y-m-d h:i:s ');
?〉
echo Date (' y-m-d h:i:s ');
?〉
Output Current time: 2008-10-12-02:32:17
Strange, the actual time is: 2008-10-12-10:32:17
is PHP date () 8 hours less than the correct time?
Take a look at the PHP manual "Example 1." Date () example "The first line has one more time zone set
Set the default time zone to use. Available from PHP 5.1
Date_default_timezone_set (' UTC ');
Originally php5.1. Start, PHP.ini added date.timezone this option, by default, is closed, that is, the time displayed (no matter what PHP command) is Greenwich Mean Time, and Beijing time is just 8 hours.
How to set up can get the correct PHP time.
1, modify the php.ini. Open php.ini Find Date.timezone Remove the preceding semicolon = add Asia/shanghai After, restart Apache server can--the disadvantage is that if the program
Put on someone else's server, can not modify the php.ini, that will not be.
2, in the program to add time to initialize the statement that is: "Date_default_timezone_set (" Asia/shanghai "); "This can be arbitrarily set by the programmer, my recommendation."
Time zone identifiers, the values available in mainland China are: prc,asia/chongqing, Asia/shanghai, Asia/urumqi (Chinese, Chongqing, Shanghai, Urumqi, respectively), Etc/gmt-8,asia/harbin
Taiwan available: Asia/macao, Asia/hong_kong, Asia/taipei (Macau, Hong Kong, Taipei) and Singapore: Asia/singapore
It is time for Beijing to achieve the output.
More detailed time zone code time zone codes Time zone index code timezone_identifier you can find it on the official website.
http://www.bkjia.com/PHPjc/477500.html www.bkjia.com true http://www.bkjia.com/PHPjc/477500.html techarticle Beginners PHP To do the site, want to get the current time on the page, learn programming people know the time function date (), first Use this function to format a local time/date, first write a test generation ...