Here to introduce the difference between the PHP date function, here is mainly about the date and gmdate the use of the difference, the need for friends can refer to.
date-formatting a local time/date
The Date/time function allows you to extract and format the date and time on the server.
Note: These functions depend on the local settings of the server.
Installation
The Date/time function is part of the PHP core. These functions can be used without installation.
Runtime Configuration
The behavior of the date/time function is affected by the settings in php.ini.
Date/time configuration options:
Name default description can be changed
Date.default_latitude "31.7667" specifies the default latitude (available starting with PHP 5). Date_sunrise () and Date_sunset () Use this option. Php_ini_all
Date.default_longitude "35.2333" specifies the default longitude (available starting with PHP 5). Date_sunrise () and Date_sunset () Use this option. Php_ini_all
Date.sunrise_zenith "90.83" Specifies Sunrise Zenith (available starting from PHP 5). Date_sunrise () and Date_sunset () Use this option. Php_ini_all
Date.sunset_zenith "90.83" Specifies Sunset Zenith (available starting from PHP 5). Date_sunrise () and Date_sunset () Use this option. Php_ini_all
Date.timezone "" Specifies the default time zone (available starting with PHP 5.1). Php_ini_all
The Gmdate () function formats the GMT/UTC date/time.
Similar to the date () function, the difference is that the time returned is Greenwich Mean Time (GMT).
Grammar
Gmdate (Format,timestamp)
Parameter description
Format is optional. Specifies how the results are returned.
Timestamp is optional.
Hints and Notes
Note: Before PHP 5.1.0, negative timestamps (dates before 1970) do not work under some systems (for example, Windows).
For example, we are now in the time zone is +8, then the server run the following script to return the time should be this:
The current time is assumed to be 2007-03-14 12:15:27
The code is as follows |
Copy Code |
echo Date (' y-m-d h:i:s ', Time ()); Output is: 2007-03-14 12:15:27 echo gmdate (' y-m-d h:i:s ', Time ()); Output is: 2007-03-14 04:15:27 |
But this is only the result of running PHP under Linux+apache, if run under Windows, then 2 functions returned are: 2007-03-14 04:15:27.
Therefore, we should give a compatibility of the wording, unified use of gmdate, and manually set the current time zone, the following improvements:
The code is as follows |
Copy Code |
echo gmdate (' y-m-d h:i:s ', time () + 3600 * 8); |
So no matter under the Linux+apache or windows are getting the correct results, of course, there is a benefit to write, when the site is facing the world, then the site users as long as the settings in the time zone, the program automatically based on the time zone set by the user to calculate, The publication time of the information in the database is only the time that is generated by the current date (), then the published time in China + 8 time zone is: 2007-03-14 12:15:27, then in Europe + 2 time zone users see this information published: 2007-03-14 06:15:27, the time for this information is all right.
http://www.bkjia.com/PHPjc/445325.html www.bkjia.com true http://www.bkjia.com/PHPjc/445325.html techarticle here to introduce the difference between the PHP date function, here is mainly about the date and gmdate the use of the difference, the need for friends can refer to. Date format a local time/date ...