Php obtains the server time (solving the eight-hour gap problem). The following three obtain the current time to solve the eight-hour gap problem, you only need to add date_default_timezone_set (\ "Asia/Chongqing \"); To solve the time zone problem. Generally, the date () and time () functions will have time difference issues.
Php tutorial to get server time (solve the problem of 8 hours gap)
The following three methods can solve the eight-hour gap. You only need to add date_default_timezone_set ("asia/chongqing") before obtaining the time, generally, the date () and time () functions have time difference issues.
/**
* Get the current server Date and Time
*/
Function get_server_datetime ()
{
Date_default_timezone_set ("asia/chongqing ");
Return date ("y-m-d h: I: s ");
}
/**
* Get the current server date
*/
Function get_server_date ()
{
Date_default_timezone_set ("asia/chongqing ");
Return date ("ymd ");
}
/**
* Get the current server time
*/
Function get_time ()
{
Date_default_timezone_set ("asia/chongqing ");
$ Timeval ["h"] = date ("h"); // hour
$ Timeval ["I"] = date ("I"); // minute
$ Timeval ["s"] = date ("s"); // second
Return $ timeval;
}